locked
HttpWebResponse - The remote server returned an error: (500) Internal Server Error. RRS feed

  • Question

  • User-696158525 posted

     HI,

    I am developing an application which I need to send SOAP messages. I can create the message and send it to the appropiate destinations but when trying to get a response it gives me an error :

    The remote server returned an error: (500) Internal Server Error.

    the code that i created for the transport layer is as follow

         public string SendSoapMessage(string soapMsg, string dest)
            {
                ASCIIEncoding encoding = new ASCIIEncoding();
                byte[] data = encoding.GetBytes(soapMsg);
                // Prepare web request...
                HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(dest);

                myRequest.KeepAlive = true;
                myRequest.AllowAutoRedirect = true;

                myRequest.Method = "POST";
                myRequest.ContentType = "application/soap+xml";
                myRequest.ContentLength = data.Length;
                Stream newStream = myRequest.GetRequestStream();
                // Send the data.
                newStream.Write(data, 0, data.Length);
                newStream.Close();

                HttpWebResponse webresponse = (HttpWebResponse)myRequest.GetResponse(); 
                Encoding enc = System.Text.Encoding.GetEncoding(1252);
                StreamReader loResponseStream = new
                StreamReader(webresponse.GetResponseStream(), enc);
                string response = loResponseStream.ReadToEnd();
                loResponseStream.Close();
                webresponse.Close();

                return response; //SoapInterpreter.DecomposeSoapMessage(response);
            }

    I get the error in the line marked bold, I am pretty new to SOAP development and I don't really know how to fix it.
    I am trying debuging to development enviornment, I mean that this application is not published to IIS.

    Have any of you idea how to fix it ?

    Thank You in advance!

    Wednesday, September 30, 2009 10:35 AM

Answers

  • User1696475319 posted

    You don't have to make an HttpWebRequest call to a SOAP service.  In Visual Studio, you can right click the project and add a web/service reference.  Specify the URL to your SOAP service and it will generate proxy classes for you.  You then use that proxy class and call its methods - the proxy class will take care of sending the SOAP envelope and body across, all you have to do is supply the methods with the right parameters.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 30, 2009 5:01 PM

All replies

  • User694699059 posted

    Use a tool like Fiddler to see how the actual messgae you send looks like and compare it to a messgae which you know that works. Same goes for the http headers.

    One option is that you should add to the request an HTTP header "SoapAction" with the value the server requires.

    Wednesday, September 30, 2009 12:44 PM
  • User1696475319 posted

    You don't have to make an HttpWebRequest call to a SOAP service.  In Visual Studio, you can right click the project and add a web/service reference.  Specify the URL to your SOAP service and it will generate proxy classes for you.  You then use that proxy class and call its methods - the proxy class will take care of sending the SOAP envelope and body across, all you have to do is supply the methods with the right parameters.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 30, 2009 5:01 PM
  • User899761514 posted

    Now,I am learning Web Service.

    Tuesday, March 26, 2013 12:13 AM