add

Web Services – SOAP part 4

Web Service concepts – SOAP , UDDI , WSDL

In Previous section Web Services Part3, we discussed few
fundamental concepts on Web Services and introduction to SOAP protocol.

In this part, Lets talk more about SOAP protocol and some other protocols it take support to for an end to end communication.

SOAP uses the web services Description Language or WSDL(even this is a w3C standard) is a prototype that relies on XML for modelling , describing ,locating and  publishing the web services.  A WSDL document contains the details of the input and output types for a web service and its locations, call types and it serves a model for developers for building a web Service client that could communicate with a web service.

How SOAP Works ?

SOAP relies on XML due to benefits of interoperability between platforms and applications also it has a predefined structure in which data is sent and received between the disparate applications to communicate.

We perform below basic steps before we could initiate a SOAP web service :

  • lookup/search  for a service : browse the Web service Directory using UDDI.
  • subscribe to the Service :  get the WSDL document
  • frame the contract : Examine the Input/output type, location and call types in WSDL document.

From the last step , we create a client stub or program with a proper interface to send and receive the SOAP  messages to and from the web service.

Lets talk about SOAP Specification.

SOAP specification mainly consists of 4 parts :

SOAP description –  contains SOAP message level Description
Serialization of SOAP messages – this lists the rules for serialization of SOAP request/response ,messages over the network.
protocol Binding – This defines the binding of SOAP service to the transport protocol.
Remote procedural call Binding – contains type of RPC binding.

SOAP 1.1 and SOAP 1.2 are the two standard specifications available as of now. SOAP mostly uses HTTP transport as it could tunnel through port 80 on majority of firewalls.

now, you might ask me on how do my soap service provider/requester determine if a particular SOAP request message/response message confirms to either  SOAP 1.1 or SOAP 1.2 ?

SOAP messages normally qualify the SOAP envelope with a different namespace, depending on the SOAP version.

Below Examples shows the SOAP 1.1 and 1.2 version of the namespace.

 

SOAP 1.1 Message :

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schema.xmlsoap.org/soap/envelope/
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header>
<secureInfo xmlns="http://www.dummy.secureInfo.com/sec">
<username>xxxxxx</username>
<password>xxxxxx</password>
</secureInfo>
</soap:Header>
<soap:Body>
<!-- The SOAP message Body goes here ... -->
</soap:Body>
</soap:Envelope>

SOAP 1.2 Message :

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header>
<secureInfo xmlns="http://www.dummy.secureInfo.com/sec">
<username>xxxxxx</username>
<password>xxxxxx</password>
</secureInfo>
</soap:Header>
<soap:Body>
<!-- The SOAP message Body goes here ... -->
</soap:Body>
</soap:Envelope>

Now lets talk a bit more about header block. We can control who can consume the header block by using two available attributes actor

and role. In SOAP 1.1 message, you can specify first intermediary to consume the header block by defining the actor attribute with the URI.

Example :

<soap:Header>
<secureInfo soap:actor="http://schemas.xmlsoap.org/soap/actor/next" xmlns="http://www.dummy.secureInfo.com/sec">
<username>xxxxxx</username>
<password>xxxxxx</password>
</secureInfo>
</soap:Header>

In SOAP 1.2 message, the role attribute provides more control on how intermediaries handle the SOAP message.

We can specify a header block  to be consumed by :

only first intermediary : we use URI soap:role=”http://schemas.xmlsoap.org/soap/role/next”

Not any particular intermediary :  soap:role=”http://www.w3.org/2003/05/soapenvelope/role/none”

For Last Intermediary : we use soap:role=”http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver” ( default in SOAP 1.2)

Also, there’s an optional attribute with default value “false”  ( soap 1.1 has values 0 or 1) called “mustUnderstand” to control if the header block is mandatory to be processes by recipients.

SOAP Error Messages : SOAP 1.1 and SOAP 1.2 deal the SOAP errors in different way.

SOAP 1.1 Error messages includes the elements as below :

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<soap:Body>
<soap:Fault>
<faultcode>soap:client.missing Parameter</faultcode>
<faultstring>Parameter missing in input request</falsestring>
<faultactor>http://example.com/myservice</faultactor>
<detail>
<pay:error xmlns:pay="http://www.example.com/payerr">
<pay:errorDescription> pay channel source missing</pay:errorDescription>
<code>219</code>
</detail>
</soap:Fault>

</soap:Body>
</soap:Envelope>

SOAP 1.2 Error message includes slightly different elements … ( Bold Tags indicate those tags are required)

<soap:Fault>
<soap:Code>
<soap:Value>soapVersionMatch | soap:MustUnderstand|Sender|DataEncodingUnknown|Receiver</soap:Value>
<soap:Subcode>
<soap:Value>random text</soap:Value>
<soap:Subcode> ... </soap:Subcode>
</soap:Subcode>
</soap:Code>
<Soap:Reason><soap:Text xml:lang="languageCode">test</soap:Text>
<soap:Text xml:lang="languageCode">text<soap:Text>
</soap:Reason>
<soap:Node>http://www.example.com/testservice</soap:Node>
<soap:Role>http://www.example.com/serv/</soap:Role>
<soap:Detail> ... </soap:Detail>

 

SOAP Supported data Types :

SOAP Specification relies on XSD schema datatypes for defining the soap messages.

It supports both Primitive datatypes , simple complex data types and complex datatypes built by primitive and simpletypes and custom structures.

below are the qualified datatypes supported by xsd specification : ( reference : Oracle docs)

xsd:base64Binary: Base64-encoded binary data.

xsd:boolean: Binary data (true [non-zero] or false [0]).

xsd:byte: Short data between -128 and 127.

xsd:double: IEEE double-precision 64-bit floating point data.

xsd:float: IEEE single-precision 32-bit floating point data.

xsd:hexBinary: Arbitrary hex-encoded binary data.

xsd:int: Long data between -2147483648 and 2147483647.

xsd:short: Integer data between -32768 and 32767.

xsd:signedInt: Integer data between -2147483648 and 2147483647.

xsd:string: A null-terminated character string.

xsd:unsignedByte: Unsigned, short data no greater than 255.

xsd:unsignedInt: Unsigned, long data no greater than 4294967295.

xsd:unsignedShort

Unsigned, short data no greater than 65535.

 

WSDL ( Web Service Description Language ) :

Lets talk a bit on WSDL in this section. Web Service Description Language or WSDL is basically a contract/model for the interface of  a web service.  WSDL document also relies on XML specification and grammar for simplicity and platform independence.

WSDL 1.1 uses below to define a Web service:

Types – A container for data type definitions using some type system (such as XSD elements).
Message – An abstract, typed definition of the data being communicated.
Operation – An abstract description of an action supported by the service.
Port Type – An abstract set of operations supported by one or more endpoints.
Binding – A concrete protocol and data format specification for a particular port type.
Port – A single port defined as a combination of a binding and a network address.
Service – A collection of related ports

 

 

 

 

 

 

 

 

 

 

 

Version 2.0 Specification of WSDL and it’s comparison with WSDL 1.1 Specification :

WSDL 1.1 and 2..0 comparision

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Sample WSDL Document :   ( reference Example from : https://www.oasis-open.org/)

<?xml version="1.0" encoding="utf-8"?>
<definitions name="StockQuote" targetNamespace="http://example.com/stockquote/"
xmlns:tns="http://example.com/stockquote/"
xmlns:xsd1="http://example.com/stockquote/schema/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<schema
targetNamespace="http://example.com/stockquote/schema/"
xmlns="http://www.w3.org/2001/XMLSchema">
<element name="TradePriceRequest">
<complexType>
<all>
<element name="tickerSymbol" type="string"/>
</all>
</complexType>
</element>
<element name="TradePrice">
<complexType>
<all>
<element name="price" type="float"/>
</all>
</complexType>
</element>
</schema>
</types>
<message name="GetLastTradePriceInput">
<part name="body" element="xsd1:TradePriceRequest"/>
</message>
<message name="GetLastTradePriceOutput">
<part name="body" element="xsd1:TradePrice"/>
</message>
<portType name="StockQuotePortType">
<operation name="GetLastTradePrice">
<input message="tns:GetLastTradePriceInput"/>
<output message="tns:GetLastTradePriceOutput"/>
</operation>
</portType>
<binding name="StockQuoteSoapBinding" type="tns:StockQuotePortType">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="GetLastTradePrice">
<soap:operation
soapAction="http://example.com/GetLastTradePrice"/>
<input>   <soap:body use="literal"/></input>
<output><soap:body use="literal"/></output>
</operation>
</binding>
<service name="StockQuoteService">
<port name="StockQuotePort" binding="tns:StockQuoteSoapBinding">
<soap:address location="http://location/sample"/>
</port>
</service>
</definitions>

We will discuss the Publish , discover , subscribe and invoke cycle of SOAP web Services in Web Services Part 5 - SOAP,UDDI and WSDL.

Written by Ramesh Metta


Leave a Reply

Your email address will not be published. Required fields are marked *

*
*