SOAP 1.1
The following is a sample SOAP 1.1 request and response. The placeholders shown need to be replaced with actual values.
Expand|Select|Wrap|Line Numbers
- POST /testdb/UnitReporting.asmx HTTP/1.1
- Host: localhost
- Content-Type: text/xml; charset=utf-8
- Content-Length: length
- SOAPAction: "http://mylocation/UpdateInformation"
- <?xml version="1.0" encoding="utf-8"?>
- <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
- <soap:Body>
- <UpdateInformation xmlns="http://mylocation/">
- <WhenSent>dateTime</WhenSent>
- <StatusMessage>string</StatusMessage>
- </UpdateInformation>
- </soap:Body>
- </soap:Envelope>
Expand|Select|Wrap|Line Numbers
- POST /testdb/UnitReporting.asmx/UpdateInformation HTTP/1.1
- Content-Type: text/xml; charset=utf-8
- SOAPAction: http://mylocation/UpdateInformation
- Content-Length: 450
- Host: localhost
- <?xml version="1.0" encoding="utf-8"?>
- <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
- <soap:Body>
- <UpdateInformation xmlns="http://mylocation/">
- <WhenSent>12/30/2008 3:28:01 PM</WhenSent>
- <StatusMessage>Nothing to report</StatusMessage>
- </UpdateInformation>
- </soap:Body>
- </soap:Envelope>
Expand|Select|Wrap|Line Numbers
- HTTP/1.1 500 Internal Server Error
- Server: Microsoft-IIS/5.1
- Date: Tue, 30 Dec 2008 20:28:02 GMT
- X-Powered-By: ASP.NET
- X-AspNet-Version: 2.0.50727
- Cache-Control: private
- Content-Type: text/plain; charset=utf-8
- Content-Length: 236
- System.InvalidOperationException: Request format is invalid: text/xml; charset=utf-8.
- at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters()
- at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
If I use a regular old POST urlencoded style, i am able to execute the function fine, but trying to do soap fails saying the contenttype is wrong?
Any ideas?
Edit: The (correct version) code I use to produce this:
Expand|Select|Wrap|Line Numbers
- private static bool DoSoap11Style()
- {
- bool retval = false;
- try
- {
- string test = "http://localhost/testdb/UnitReporting.asmx/UpdateInformation";
- HttpWebRequest hwr = (HttpWebRequest)HttpWebRequest.Create(test);
- hwr.Method = "POST";
- hwr.ContentType = "text/xml; charset=utf-8";
- hwr.Headers.Add("SOAPAction", "http://mylocation/UpdateInformation");
- string postData = GetPostDataSoap11();
- byte[] byte1 = Encoding.UTF8.GetBytes(postData.ToString());
- hwr.ContentLength = byte1.Length;
- Stream newStream = hwr.GetRequestStream();
- newStream.Write(byte1, 0, byte1.Length);
- newStream.Close();
- HttpWebResponse hresp = (HttpWebResponse)hwr.GetResponse();
- }
- catch (Exception ee)
- {
- bool ignoreme = (ee.Message == "");
- retval = false;
- }
- return retval;
- }
- private static string GetPostDataSoap11()
- {
- StringBuilder postData = new StringBuilder("");// "firstone=" + "";
- postData.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n");
- postData.Append("<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\r\n");
- postData.Append(" <soap:Body>\r\n");
- postData.Append(" <UpdateInformation xmlns=\"http://mylocation/\">\r\n");
- postData.AppendFormat(null, " <WhenSent>{0}</WhenSent>\r\n", DateTime.Now);
- postData.AppendFormat(null, " <StatusMessage>{0}</StatusMessage>\r\n", "Nothing to report");
- postData.Append(" </UpdateInformation>\r\n");
- postData.Append(" </soap:Body>\r\n");
- postData.Append("</soap:Envelope>\r\n");
- return postData.ToString();
- }