473,413 Members | 1,807 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

accessing webservice with soap

Plater
7,872 Expert 4TB
I have a webservice that claims the following:

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
  1. POST /testdb/UnitReporting.asmx HTTP/1.1
  2. Host: localhost
  3. Content-Type: text/xml; charset=utf-8
  4. Content-Length: length
  5. SOAPAction: "http://mylocation/UpdateInformation"
  6.  
  7. <?xml version="1.0" encoding="utf-8"?>
  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/">
  9.   <soap:Body>
  10.     <UpdateInformation xmlns="http://mylocation/">
  11.       <WhenSent>dateTime</WhenSent>
  12.       <StatusMessage>string</StatusMessage>
  13.     </UpdateInformation>
  14.   </soap:Body>
  15. </soap:Envelope>
  16.  
Now I tried to produce this using HttpWebRequest and sent the following(pulled from a packet watcher):
Expand|Select|Wrap|Line Numbers
  1. POST /testdb/UnitReporting.asmx/UpdateInformation HTTP/1.1
  2. Content-Type: text/xml; charset=utf-8
  3. SOAPAction: http://mylocation/UpdateInformation
  4. Content-Length: 450
  5. Host: localhost
  6.  
  7. <?xml version="1.0" encoding="utf-8"?>
  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/">
  9.   <soap:Body>
  10.     <UpdateInformation xmlns="http://mylocation/">
  11.       <WhenSent>12/30/2008 3:28:01 PM</WhenSent>
  12.       <StatusMessage>Nothing to report</StatusMessage>
  13.     </UpdateInformation>
  14.   </soap:Body>
  15. </soap:Envelope>
  16.  
For return result:
Expand|Select|Wrap|Line Numbers
  1. HTTP/1.1 500 Internal Server Error
  2. Server: Microsoft-IIS/5.1
  3. Date: Tue, 30 Dec 2008 20:28:02 GMT
  4. X-Powered-By: ASP.NET
  5. X-AspNet-Version: 2.0.50727
  6. Cache-Control: private
  7. Content-Type: text/plain; charset=utf-8
  8. Content-Length: 236
  9.  
  10. System.InvalidOperationException: Request format is invalid: text/xml; charset=utf-8.
  11.    at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters()
  12.    at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
  13.  

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
  1. private static bool DoSoap11Style()
  2. {
  3.     bool retval = false;
  4.     try
  5.     {
  6.         string test = "http://localhost/testdb/UnitReporting.asmx/UpdateInformation";
  7.         HttpWebRequest hwr = (HttpWebRequest)HttpWebRequest.Create(test);
  8.         hwr.Method = "POST";
  9.         hwr.ContentType = "text/xml; charset=utf-8";
  10.         hwr.Headers.Add("SOAPAction", "http://mylocation/UpdateInformation");
  11.  
  12.         string postData = GetPostDataSoap11();
  13.         byte[] byte1 = Encoding.UTF8.GetBytes(postData.ToString());
  14.         hwr.ContentLength = byte1.Length;
  15.         Stream newStream = hwr.GetRequestStream();
  16.         newStream.Write(byte1, 0, byte1.Length);
  17.         newStream.Close();
  18.  
  19.         HttpWebResponse hresp = (HttpWebResponse)hwr.GetResponse();
  20.     }
  21.     catch (Exception ee)
  22.     {
  23.         bool ignoreme = (ee.Message == "");
  24.         retval = false;
  25.     }
  26.     return retval;
  27. }
  28.  
  29. private static string GetPostDataSoap11()
  30. {
  31.     StringBuilder postData = new StringBuilder("");// "firstone=" + "";
  32.     postData.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n");
  33.     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");
  34.     postData.Append("  <soap:Body>\r\n");
  35.     postData.Append("    <UpdateInformation xmlns=\"http://mylocation/\">\r\n");
  36.     postData.AppendFormat(null, "      <WhenSent>{0}</WhenSent>\r\n", DateTime.Now);
  37.     postData.AppendFormat(null, "      <StatusMessage>{0}</StatusMessage>\r\n", "Nothing to report");
  38.     postData.Append("    </UpdateInformation>\r\n");
  39.     postData.Append("  </soap:Body>\r\n");
  40.     postData.Append("</soap:Envelope>\r\n");
  41.  
  42.     return postData.ToString();
  43. }
Dec 30 '08 #1
1 5944
Plater
7,872 Expert 4TB
And in typical fashion, the problem turned out to be the one thing I thought for sure was right:
http://localhost/testdb/UnitReporting.asmx/UpdateInformation
is used for regular POST, while
http://localhost/testdb/UnitReporting.asmx
is used for soap connections.

REDIT: I guess I had read something wrong, the best working format I have found for soap requests is this:
string datetimeformat = @"yyyy-MM-ddTHH:mm:ss"

Everything else results in the original "local" time transfered to be normalized to the server's local timezone
Dec 30 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Hans Kesting | last post by:
Hi, I'm trying to create a client for some webservice. BUT I have only limited information: * no WSDL available ("expected Q1-06") (it seems to be written in Java) * I don't have access (yet)...
1
by: Jinashe | last post by:
what do i need to enable accessing of webservices from a clients PC i'm hosting some webservices from my server in VB.NET. i've got some client windows applications done in VB.NET. what have i...
7
by: stephan querengaesser | last post by:
hi ng, i try to invoke a webservice-method with an filter-object, that contains value types. if i don´t want to filter the return value of the method, i have to pass a new instance of the...
7
by: Christian Wilhelm | last post by:
Hi! I'm trying to call a Java WebService out of a .net Client. There are two Methods, one Method requires one Parameter of type Parameter, the other Method requires one Parameter of type...
7
by: Nalaka | last post by:
Hi, I created a sinple web service that returns a dataSet. Then I created a client program that uses this web service (that returns the Dataset). My question is, how did the client figure...
4
by: Kaush | last post by:
Hi all, I am creating a webservice to accept SOAP messages, parse the message and send a SOAP response back to the client accessing my web service using WSE-2 in ASP.NET. I am creating a class...
1
by: jens Jensen | last post by:
Hello , i'm calling a webservice generated with oracle webservice java tools. I'm not able to add a web reference to a .net client the usual way with visual studio 2005. I was therefore...
0
by: rakeshkumawat | last post by:
I am facing a problem while reading the result which is loaded in DOMDocument. In which I am sending a request to web service and getting a record of Single Order. This is my VB Code which is i am...
5
by: VictorG | last post by:
Hello, I am trying to secure a webservice using WSE 3.0 and the turnkey usernameForCertificateSecurity profile. I am passing a valid username token, and on the server I have overridden the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.