How SOAP Works

by Emanuela Hedrick.

Share
|
Homepage | Submit your article | Contact | TOS
More articles on apis and web feeds  

You are here: Categories » Internet » APIs and Web Feeds

A SOAP request will involve creating and populating a request envelope, which contains all the required information (as specified by the WSDL document), transmitting that envelope to the API server, and handling the response.

A SOAP request generally contains all of the following elements:

  • SOAP Envelope — With namespace inclusions.

  • SOAP Body — Possibly defining additional namespaces.

  • Desired Action — How the desired action is represented will depend on the API in question. It may be as simple as a parameter, or involve additional namespaces.

  • Developer Key — A unique identifier assigned by the server to the requestor.

  • Request Parameters — Detailing the request being performed.

With that information in mind, a SOAP request can be generated.

<?xmlversion="1.0" encoding=" UTF-8" standalone="no"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<devkey xsi:type="xsd:int">123</devkey>
<action xsi:type="xsd:string">search</action>
<type xsi:type="xsd:string">book</type>
<keyword xsi:type="xsd:string">style</keyword>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

The parameters included in the request are easy to pick out, and though the variable typing isn't of great importance for PHP development, it does come in handy for more strongly typed languages. The missing item here is the endpoint, made clear in the REST example because it was the URL to which the request was posted. SOAP requests, of course, are run against specified URIs, which do not need to be re-specified within the request itself.

The SOAP response would look like this:

<?xmlversion='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Body>
<LibrarySearchResponsexmlns="http://library.example.com/api/ns">
<RequestInfo>
<devkey xsi:type=" xsd:string">123</devkey>
<action xsi:type="xsd:string">search</action>
<type xsi:type="xsd:string">book</type>
<keyword xsi:type="xsd:string">style</keyword>
</RequestInfo>
<ResponseInfo>
<ResultCount>2</ResultCount>
<Item>
<Title xsi:type="xsd:string">Style Book Vol 1</Title>
<Status xsi:type="xsd:string">Out</Status>
<Holds xsi:type="xsd:int">3</Holds>
<CopiesOnHand xsi:type="xsd:int">2</CopiesOnHand>
<Author xsi:type="xsd:string">Jon Doe</Author>
</Item>
<Item>
<Title xsi:type="xsd:string">Style Book Vol 2</Title>
<Status xsi:type="xsd:string">In</Status>
<Holds xsi:type="xsd:int">0</Holds>
<CopiesOnHand xsi:type="xsd:int">1</CopiesOnHand>
<Author xsi:type="xsd:string">Jon Doe</Author>
</Item>
</ResponseInfo>
</LibrarySearchResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

The SOAP response isn't too different from the REST response shown earlier. In fact, much of the name spacing could actually be omitted (though it is rare to see a SOAP response without it), at which point, with the exception of the additional encapsulation, the two documents would be very similar.

As you should be able to discern from the response shown, it declares itself to be XML 1.0 and uses UTF-8 for encoding. The SOAP-ENV:Envelope element is the root element for the document, and has threenamespaces, including the SOAP-ENV namespace. The Body then contains the LibrarySearchResponse element among other things, which also defines its own namespace.

The RequestInfo parent follows after, and this contains the request parameters that generated the response that follows on from there. Returning request parameters with the response is a common occurrence in SOAP.

Finally, the response itself is returned. Notice that the ResultCount element sits as a direct child of ResponseInfo, and the result items themselves are again stored under a repeating element, Item.

Leave a comment or ask a question
Total comments: 0

APIs and Web Feeds Disclaimer

  • The e-articles directory is not responsible for any and all copyright infringements by writers and authors. If you suspect the information contained by this page for any copyright infringements, please contact us to investigate the issue
REST API vs SOAP API technology - The two primary architectures for APIs are REST and SOAP. When creating your API, you really have three options: REST, SOAP, or both. REST APIs are known for being easy and quick to develop for, bu (more...)
How to implement the SOAP technology - Like REST, implementing SOAP involves both generating requests and then handling the response. Whereas handling the SOAP response is similar to the REST result, generating the SOAP request is quite (more...)
Advantages and Disadvantages of Open API - Under an open API, absolutely no security or authentication methods are used. A query is received from the wild, and the system makes its best effort to respond to it appropriately. This has severa (more...)
Common API Performance Techniques - Websites are designed to be accessed by individuals, and as such tend to rely on the relatively slow speed of the user to avoid any performance bottlenecks. This technique fails miserably wi (more...)
Introduction to Web APIs ~ REST vs SOAP - When interacting with web services, generally the choice of which method to use will be made for you. The majority of services operate in either REST or SOAP, not both (Amazon is a notable exceptio (more...)
What are Feeds ~ RSS and ATOM Feed Specifications - You can think of feeds as small modules of information that can be plugged into existing websites, consumed by clients on their desktop, or consumed by aggregators to be presented by users with oth (more...)
Important Considerations When Using Feeds - XML feeds provide a great resource of information, but their use is not without its own special considerations. Security and legal concerns go hand in hand whether you are producing or consuming (more...)
Advantages and Disadvantages of Client Side Certificates - The API server can generate a certificate and provide it to the client via a secure channel before any requests are made. This certificate is then used in the authentication process; this confirms (more...)
How to implement the REST technology - There are two sides to this tale, the first is how to generate legitimate REST requests, and the second is how to handle the responses correctly. Generating Requests When i (more...)
Why Do You Need to Produce Feeds - Feeds have several advantages, primarily related to consumption, over traditional HTML formats. Many desktop applications are devoted to reading feeds at regular intervals, and many of the new batc (more...)

 
free content
    Copyright © 2006 - 2012 e-articles.info.
The texts, articles and tutorials in the directory are property of their respective owners and authors.