none
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=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:zz=\"http://integration.starcite.com/\">"
       +"<soapenv:Header>" +
          "<wsse:Security soapenv:mustUnderstand=\"1\" xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\">" +
             "<wsse:UsernameToken wsu:Id=\"UsernameToken-1\" xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">" +
                "<wsse:Username>UserId</wsse:Username>" +
                "<wsse:Password Type=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText\">Password</wsse:Password>" +
                "<wsse:Nonce EncodingType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary\">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>" +
    "</soapenv:Envelope>";
    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 );
    streamWriter.Close();
    System.IO.StreamReader streamReader =
    new System.IO.StreamReader(
    request.GetResponse().GetResponseStream() );
    string strResponse = "";
    while( !streamReader.EndOfStream )
    strResponse += streamReader.ReadLine();
    streamReader.Close();

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

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:zz="http://integration.starcite.com/">
       <soapenv:Header>
          <wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
             <wsse:UsernameToken wsu:Id="UsernameToken-1" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
                <wsse:Username>UserName</wsse:Username>
                <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">Password</wsse:Password>
                <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">rqgwyErTk7l5l7t1DqhdKw==</wsse:Nonce>
                <wsu:Created>2013-05-31T17:49:07.888Z</wsu:Created>
             </wsse:UsernameToken>
          </wsse:Security>
       </soapenv:Header>
       <soapenv:Body>
          <zz:search-meeting-request>
             <filter from="0" to="50">
                <meetingId comparator="equal">28</meetingId>
             </filter>
          </zz:search-meeting-request>
       </soapenv:Body>
    </soapenv:Envelope>

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

Answers

  • 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
    Moderator