SOAP

 
Chapter 15 - Web Services
bySimon Robinsonet al.
Wrox Press 2002
  

As mentioned above, one method used to exchange data with Web Services is SOAP. This technology has had a lot of press, especially since Microsoft decided to adopt it for use in the .NET Framework. Now, though, the excitement seems to be dying down a bit as the SOAP specification is finalized. When you think about it, finding out exactly how SOAP works is a bit like finding out about how HTTP works  interesting, but not essential. Most of the time we never have to worry about the format of the exchanges made with Web Services, they just happen, we get the results we want, and everyone is happy.

For this reason we won't go into a huge amount of depth in this section, but we will see some simple SOAP requests and responses so you can get a feel for what is going on under the hood should you so desire .

Let's imagine that we want to call a method in a Web Service with the following signature:

   int DoSomething(string stringParam, int intParam)   

The SOAP headers and body required for this are shown below, with the address of the Web Service (more on this later) at the top:

   POST /SomeLocation/myWebService.asmx HTTP/1.1     Host: karlivaio     Content-Type: text/xml; charset=utf-8     Content-Length: length     SOAPAction: "http://tempuri.org/DoSomething"     <?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>     <DoSomething xmlns="http://tempuri.org/">     <stringParam>string</stringParam>     <intParam>int</intParam>     </DoSomething>     </soap:Body>     </soap:Envelope>   

The length parameter here specifies the total byte size of the content, and will vary depending on the values sent in the string and int parameters.

The soap namespace referenced here defines various elements that we use to build up our message. When we send this over HTTP the actual data sent will be slightly different (but related ). For example, we could call the above method using the simple GET method:

   GET /PCSWebSrv1/Service1.asmx/DoSomething?stringParam=string&intParam=int HTTP/1.1     Host: hostname   

The SOAP response of this method will be as follows :

   HTTP/1.1 200 OK     Content-Type: text/xml; charset=utf-8     Content-Length: length     <?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>     <DoSomethingResponse xmlns="http://tempuri.org/">     <DoSomethingResult>int</DoSomethingResult>     </DoSomethingResponse>     </soap:Body>     </soap:Envelope>   

where length is again varied according to the contents, in this case int .

Again, the actual response over HTTP may be far simpler, for example:

   HTTP/1.1 200 OK     Content-Type: text/xml; charset=utf-8     Content-Length: length     <?xml version="1.0"?>     <int xmlns="http://tempuri.org/">int</int>   

This is a far simpler XML format.

As discussed at the start of this section, the beauty of all this is that we can ignore it completely. It is only if we want to do something really odd that the exact syntax becomes important.

  


Professional C#. 2nd Edition
Performance Consulting: A Practical Guide for HR and Learning Professionals
ISBN: 1576754359
EAN: 2147483647
Year: 2002
Pages: 244

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net