Link to home
Start Free TrialLog in
Avatar of Kiran_M
Kiran_M

asked on

Why am i getting "The remote server returned an error : (500) Internal Server Error" when i consume .net Web Service

I have .net C# Test Harness consuming a new WebService  I wrote.  I am getting  "The remote server returned an error : (500) Internal Server Error"  when it executes
 WebResponse webResponse = webRequest.GetResponse();

My Test Harness code to invoke Web Service is as follows :

private void CallUsingSOAP(string InXml, out XmlDocument xmlResponse)
        {
              string strSoapRequest = "";
             xmlResponse = null;
      string strABCWebServiceUrl = ConfigurationManager.AppSettings["ABCTestWebServiceURL"];
      
                  strSoapRequest = "";
                  strSoapRequest +=      "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
                  strSoapRequest +=      "<soap:Envelope ";
                  strSoapRequest +=      "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ";
                  strSoapRequest +=      "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" ";
                  strSoapRequest +=      "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" ";
                  strSoapRequest +=      "xmlns=\"http://www.ACORD.org/standards/PC_Surety/ACORD1.10.0/xml/\" ";
                  strSoapRequest +=      ">";
                  strSoapRequest +=      "<soap:Header>";
                  strSoapRequest +=      "<ContractId/> ";
                  strSoapRequest +=      "<AppInfo/> ";
                  strSoapRequest +=      "</soap:Header>";
                  strSoapRequest +=      "<soap:Body>";
                  strSoapRequest +=   InXml;
                  strSoapRequest +=      "</soap:Body>";
                  strSoapRequest +=      "</soap:Envelope>";
            try
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(strSoapRequest);

                HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(strABCWebServiceUrl);

                webRequest.Headers.Add("SOAPAction", " ABCMethod");
                //webRequest.Timeout = Int32.Parse("2000");
                webRequest.ContentType = "text/xml; charset=utf-8";
                webRequest.Accept = "text/xml";
                webRequest.Method = "POST";
                Stream webStream = webRequest.GetRequestStream();
                xmlDoc.Save(webStream);
                webStream.Close();
                WebResponse webResponse = webRequest.GetResponse();
                webStream = webResponse.GetResponseStream();

                XmlTextReader xmlReader = new XmlTextReader(webStream);
      //          xmlResponse = new XmlDocument();
                xmlResponse.Load(xmlReader);
                webStream.Close();
            }
            catch (Exception e )
            {
                throw new Exception ("" + e.Message);
            }

It throws a exception when it executes the
WebResponse webResponse = webRequest.GetResponse();


The strSoapRequest  is a well formed XML, I checked it it looks ok.

I am not sure why i am getting this error?

My Web Service code is as follows :

namespace ABCTestWebService
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]

    public class ABCTestWebService :  System.Web.Services.WebService
    {
        [WebMethod]
        public XmlDocumentABCMethod (XmlDocument  InputXML)
        {
         
         }
    }

           
Avatar of strickdd
strickdd
Flag of United States of America image

I would recommend adding the Web Service as a Web Reference to the project. Then you can use it as an object type.

ABCTestWebService.ABCTestWebService  service = new ABCTestWebService.ABCTestWebService ();

server.XmlDocumentABCMethod();
Avatar of Kiran_M
Kiran_M

ASKER

I would like to use SOAP and call the web service explictly.
Then i believe you need to change this:

webRequest.Headers.Add("SOAPAction", " ABCMethod");

To this:

webRequest.Headers.Add("SOAPAction", " XmlDocumentABCMethod");
If that doesn't work, I would verify that your webservice is working properly. Either visit its location through a browser or use WebserviceSudios
Avatar of Kiran_M

ASKER

I am able to visit the web service location through a browser. Web service seems to working correctly.
Are there other reasons for this error code : 500 (Internal Server Error)?

I would recommend trying a submission to your webservice using Web Service Studio (http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=65A1D4EA-0F7A-41BD-8494-E916EBC4159C). This will help narrow down where the problem lies. I know this program works when calling a web service so it will tell you where your problem resides.

If you get a successful response, then the error lies in you calling code (which i doubt). If it also receives a 500 error, or throws and error the problem is in the web service. A good idea would be to start the web service in debug mode and step through the code if this happens. You can set it up on your localhost if you need to. You can also try creating a simple webservice and putting it on your server. See if you can contact that. If you can't you know it is a server configuration issue.

My best guess is that there is an issue in the code. It might be caused by an infinite loop or it could be caused by low RAM on the server. There are a lot of options to check.
Avatar of Kiran_M

ASKER

I'm all set with this error. The Web Service was missing Web.Service.Protocols.SoapDocumentMethodAttribute......

Thanks for your help.
ASKER CERTIFIED SOLUTION
Avatar of strickdd
strickdd
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Kiran_M

ASKER

I  was able  to fix  the problem  myself. strickdd suggestions helped a lot.