500 Internal server Error while calling a webservice through Httprequest RRS feed

  • Question

  • Hi, i am trying to call a webservice using HttpRequest as adding web reference not working for me. It asks for SOAP security header and its of wse type so i tried to call it through Httprequest. Here's my code and service request which works fine in SOAPUI.

    System.Net.HttpWebRequest request =
    (System.Net.HttpWebRequest)System.Net.WebRequest.Create("Webservice URL");
    string strSOAPRequestBody = "<soapenv:Envelope xmlns:soapenv=\"\" xmlns:zz=\"\">"
       +"<soapenv:Header>" +
          "<wsse:Security soapenv:mustUnderstand=\"1\" xmlns:wsse=\"\">" +
             "<wsse:UsernameToken wsu:Id=\"UsernameToken-1\" xmlns:wsu=\"\">" +
                "<wsse:Username>UserId</wsse:Username>" +
                "<wsse:Password Type=\"\">Password</wsse:Password>" +
                "<wsse:Nonce EncodingType=\"\">rqgwyErTk7l5l7t1DqhdKw==</wsse:Nonce>"
               + "<wsu:Created>2013-05-31T17:49:07.888Z</wsu:Created> </wsse:UsernameToken> </wsse:Security> </soapenv:Header>" +
    "<zz:search-meeting-request>" +
    "<filter from=\"0\" to=\"50\">" +
    "<meetingId comparator=\"equal\">28</meetingId>" +
    "</filter>" +
    "</zz:search-meeting-request>" +
    "</soapenv:Body>" +
    request.Method = "POST";
    request.ContentType = "application/soap+xml; charset=utf-8";
    request.ContentLength = strSOAPRequestBody.Length;
    request.UserAgent = "Apache-HttpClient/4.1.1 (java 1.5)";
    System.IO.StreamWriter streamWriter =
    new System.IO.StreamWriter( request.GetRequestStream() );
    streamWriter.Write( strSOAPRequestBody );
    System.IO.StreamReader streamReader =
    new System.IO.StreamReader(
    request.GetResponse().GetResponseStream() );
    string strResponse = "";
    while( !streamReader.EndOfStream )
    strResponse += streamReader.ReadLine();

    Following is the request that i put in SOAP UI and its working fine.

    <soapenv:Envelope xmlns:soapenv="" xmlns:zz="">
          <wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="">
             <wsse:UsernameToken wsu:Id="UsernameToken-1" xmlns:wsu="">
                <wsse:Password Type="">Password</wsse:Password>
                <wsse:Nonce EncodingType="">rqgwyErTk7l5l7t1DqhdKw==</wsse:Nonce>
             <filter from="0" to="50">
                <meetingId comparator="equal">28</meetingId>

    Any help or guidance will be appreciated. Thanks
    Saturday, November 23, 2013 4:56 PM


  • Normally, the "500 internal server error" means that the web service threw an exception at the server side, and the server refuses to send the actual error messasge to the client for security reasons.

    There isn't much that you can do about it from the client side; you will need some access to the server in order to find the real error. If Health Monitoring is set to its default configuration, then the error will be written to the Application Log in Windows. Look for warning messages with the Category "ASP.NET". Or, if the service was written using WCF, edit the web.config and add <serviceDebug includeExceptionDetailInFaults="true"/>, to allow the error message to propagate to the client.

    • Proposed as answer by Jason Dot Wang Tuesday, November 26, 2013 9:54 AM
    • Marked as answer by Jason Dot Wang Tuesday, December 3, 2013 6:16 AM
    Saturday, November 23, 2013 9:48 PM