Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8831421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:18:18+00:00 2026-06-14T08:18:18+00:00

I am making a request to an ASMX web service as follows – private

  • 0

I am making a request to an ASMX web service as follows –

private HttpWebResponse SendSoap12Msg(string url, string method, 
                       Dictionary<string, string> KeyValue)
{
    StringBuilder SoapMessage = new StringBuilder();
    SoapMessage.Append("<?xml version='1.0' encoding='utf-8'?>");
    SoapMessage.Append(@"<soap12:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'");
    SoapMessage.Append(@" xmlns:xsd='http://www.w3.org/2001/XMLSchema'>");
    SoapMessage.Append(@" xmlns:soap12='http://www.w3.org/2003/05/soap-envelope'");
    //SoapMessage.Append(@" xmlns:soap12='http://schemas.xmlsoap.org/wsdl/soap12/'");
    SoapMessage.Append("<soap12:Body>");
    SoapMessage.Append("<");
    SoapMessage.Append(method);
    SoapMessage.Append(@" xmlns='http://tempurl.org/'>");

    foreach (KeyValuePair<string, string> kvp in KeyValue)
    {
        SoapMessage.Append("<");
        SoapMessage.Append(kvp.Key);
        SoapMessage.Append(">");
        SoapMessage.Append(kvp.Value);
        SoapMessage.Append("</");
        SoapMessage.Append(kvp.Key);
        SoapMessage.Append(">");
    }
    SoapMessage.Append("</");
    SoapMessage.Append(method);
    SoapMessage.Append(">");
    SoapMessage.Append("</soap12:Body>");
    SoapMessage.Append("</soap12:Envelope>");

    // Build HttpWebRequest
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(url));
    request.Method = "POST";
    request.ProtocolVersion = HttpVersion.Version11;
    request.ContentType = "application/soap+xml; charset=\"utf-8\"";
    //request.Accept = "application/soap+xml";

    // Send SOAP Envelope
    byte[] data = Encoding.UTF8.GetBytes(SoapMessage.ToString());
    request.ContentLength = data.Length;
    Stream requestStream = request.GetRequestStream();
    requestStream.Write(data, 0, data.Length);
    requestStream.Close();

    return (HttpWebResponse ) request.GetResponse();
}

However, whenever the request is sent, I am getting a 500 - Internal Server Error as a response. Digging deeper into the exception, using these –

catch (WebException ex)
{
    Response.ContentType = "text/html";
    Response.Write("---------- Start: A WebException occured ----------<br />");
    Response.Write("Returned Content Type: " + ex.Response.ContentType); 
    Response.Write("<br />");
    Response.Write("Is From Cache: " + ex.Response.IsFromCache);
    Response.Write("<br />");
    Response.Write("Response URI: " + ex.Response.ResponseUri.ToString());
    Response.Write("<br />");
    Response.Write("ToString: " + ex.Response.ToString());
    Response.Write("<br />");
    Response.Write("ReadToEnd: " + 
            new StreamReader(ex.Response.GetResponseStream()).ReadToEnd()); 
    Response.Write("<br />");
    Response.Write("---------- End: A WebException occured ----------");
}

I get the following output –

---------- Start: A WebException occured ----------
Returned Content Type: application/soap+xml; charset=utf-8
Is From Cache: False
Response URI: (the target uri, as expected)
ToString: System.Net.HttpWebResponse
ReadToEnd: soap:ReceiverServer was unable to process request. ---> 'soap12' is an undeclared prefix. Line 1, position 40.
---------- End: A WebException occured ----------

How can I solve it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T08:18:20+00:00Added an answer on June 14, 2026 at 8:18 am

    The only thing I see missing from the SOAP request you are building is the <request> tag after the method name and before the parameters. Omitting it will sometimes produce errors like this, or make the translation of the request to the WS entities fail.

    Try the following (omitted some things for brevity):

    SoapMessage.Append(String.Format(@"<{0} xmlns='http://tempurl.org/'>", method));
    SoapMessage.Append("<request>");    // Line added
    
    foreach (KeyValuePair<string, string> kvp in KeyValue)
    {
        SoapMessage.Append(String.Format("<{0}>", kvp.Key));
        SoapMessage.Append(kvp.Value);
        SoapMessage.Append(String.Format("</{0}>", kvp.Key));
    }
    
    SoapMessage.Append("</request>");   // Line added
    SoapMessage.Append(String.Format("</{0}>", method));
    

    Coincidently I came across this problem with a client of ours, and the missing request-tag was the cause. In some cases you can safely omit it, but sometimes it’s mandatory apparently. I also added the use of String.Format, which makes the code shorter and easier to understand.

    Edit:
    The only other thing I see missing is you setting the SOAP action in the request header. You can add it in the following manner:

    request.Headers.Add("SOAPAction:", "http://tempurl.org/YourMethodname"); 
    // You might need to try some variations. 
    // Or replacing tempurl.org with the actual domain.
    

    If you google for “C# HttpWebRequest SoapAction” your will find a lot more people getting Error 500; especially when omitting it in the request.

    See also, this blog entry which is doing almost exactly the same thing as you are trying: http://mikehadlow.blogspot.nl/2006/05/making-raw-web-service-calls-with.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a GET request against a WCF web service. My WCF service is
making a call to a web service method with nusoap returns an error array(3)
In SOAP-UI I am making a request to a web service like this: <soapenv:Envelope
I am making a synchronous request to the web service and unable to show
I am making request to web service and have to do this extending AsyncTask
I'm making a request to a JSON page using jQuery's $.getJSON method, and from
I am making a request to a service and getting a response. Service works
I am making request on server , having spaces in URL http://xxxxxxxx.com/api/api.php?func=showAllwedsdwewsdsd&params[]=Saudi%20Arab&params[]=all I was
I've a Mac VBA script making a request to a Ruby Sinatra web app.
Making a request to a RESTful service in Silverlight with HttpWebRequest works well so

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.