Web Services Types

By : |April 28, 2003 0



Web Services can be broadly classified into two categories RPC and Document style and sub-grouped
based on the encoding as Encoded or Literal. Further Web Services can be divided based on the
type of Request/Response and the Transport for carrying the SOAP messages.

Introduction

                                 

___________________________________________________________________________________________________________

Web Services is based on open standards like WSDL, SOAP and UDDI. The
description of the web service is present in the WSDL. Using the WSDL the
client application can construct SOAP messages to be sent to the server. The
WSDL contains details of the type of message to be sent like RPC or Document
style. Based on these styles the SOAP message construct differs. RPC uses SOAP
encoding and the SOAP specification defines the structure of the message.
Document style does not have any rules and a XML Document can be placed within
the SOAP Body.

Synchronous Web Services accept a request and send back the response to the
client. Hence the client waits till the response is received from the server.
In asynchronous the client does not wait and can receive a response from the
server after some time delay.

The most common form of transport for Web Services is HTTP. SOAP is a
transport independent and SOAP messages can be sent over any protocol. The
other forms of transport for SOAP are MQ/JMS and SMTP. We shall limit our
discussion to these and not cover some other transport like FTP etc that could
be used for SOAP messages.

Types

The Web Services types are:

  • Style
  • Request/Response
  • Transport

Style

There are two styles of Web Services RPC and Document. These two styles can
be SOAP Encoded or Literal. These are described in the following sections.

RPC Style: RPC style Web Services contain the method name of the remote service and
the parameters as elements within the SOAP Body. The structure of the SOAP
message and the encoding rules are governed by the SOAP specification. The
SOAP Body element contains the details for the RPC call and the
encodingStyle is set to http://schemas.xmlsoap.org/soap/encoding/
for SOAP encoding.

The following is a sample RPC style SOAP message

MSFT


Document:
Document style web service contains a XML structure within the SOAP Body.
There are no SOAP rules for the structure of the XML. Hence this can be any
XML agreed between the sender and receiver and could be based on XML Schema.

The following is a sample Document style SOAP message

Plastic Pens, Inc.

245 Yukon Drive

Phoenix

AZ

85021

88

Blue pen

250

563

Red stappler

30


Encoded:
The data sent in the SOAP message is serialized according to some encoding
rules. These encoding rules are part of the SOAP specification. In the above
RPC style the encoding is based on SOAP and we set the encoding style to http://schemas.xmlsoap.org/soap/encoding/.
The SOAP specification defines how
objects, structures, arrays and object graphs should be serialized.


Literal:
In the Literal type data is serialized according to XML Schema using XSD.
There are no special encoding rules like the Encoded style to specify how to
serialize the data that needs to be sent as part of the SOAP message.

Based on the above four combinations are possible

  • RPC/Encoded
  • RPC/Literal
  • Document/Encoded
  • Document/Literal

Most practical applications fall into two categories RPC/Encoded and
Document/Literal. Most business applications that need to exchange documents
would use Document/Literal. Examples are B2B applications where sender and
receiver have decided on the XML document to exchange and this is transferred as
part of SOAP message. Other applications that expose methods for remote calls
would tend to use RPC.

The details about the web service and the messages it supports are specified
in the WSDL. The WSDL for the web service contains a section for Binding that
specifies the type RPC or Document and the encoding for the message.

The following shows a section of the WSDL for Document/Literal and RPC/Encoded
service.

Document/Literal: 

RPC/Encoded:

More…Request/Response

Based on the request and the response Web Services can be classified into
Synchronous and Asynchronous.

Synchronous

In Synchronous services the client invokes the Web Service and waits
for the response from the server. Hence this is used when the server
responds immediately and there is no time delay to process the request.
Mostly RPC style Web Services are synchronous in nature.

The following diagram shows a synchronous stock quote service. The
client sends the stock symbol in the request and the server responds with
the quote details.

         

Asynchronous

In Asynchronous services the client invokes the Web Service but does not
wait for the response from the server. Generally document oriented Web
Services use Asynchronous, where the server receives the document does some
processing and sends back the response to the client. The implementation of
asynchronous may vary from vendor to vendor. Some approaches are

  • The server returns a ID to the client and the client periodically polls
    the server for the response.
  • If the client is a Web Service the service can callback the client.( Use
    WS-Conversation to implement Asynchronous behavior.)

The following example shows a asynchronous loan processing service using
WS-Conversation. The client sends a XML Document to the server by calling the

initiate method and gets an acknowledgement ID. The server process the loan
document and sends the response to the CallBack port of the client. If
required the client can poll the server using the acknowledgement ID.

More…Transport

The transport is the layer that carries SOAP messages. In this section
we shall look at HTTP, Message and SMTP transport for carrying SOAP
messages.

HTTP Transport

HTTP is the most common form of binding for SOAP messages. The
request message is sent over http from the client to server. The
response message from the server also travels over http to the client.
For HTTP transport the binding is set to http://schemas.xmlsoap.org/soap/http
in the WSDL.

The following shows sample SOAP request and response messages with
HTTP headers

POST /DOMService/services/DOMService HTTP/1.0Content-Type: text/xml;
charset=utf-8Accept: application/soap+xml, application/dime,
multipart/related, text/*User-Agent: Axis/1.0Host: localhostCache-Control:
no-cachePragma: no-cacheSOAPAction: ""Content-Length: 309

<?xml version="1.0" encoding="UTF-8"?>

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<soapenv:Body>

<Test>

<Ones>1</Ones>

<Two>three</Two>

</Test>

</soapenv:Body>

</soapenv:Envelope>

HTTP/1.1 200 OKContent-Type: text/xml; charset=utf-8Date: Fri, 07 Mar
2003 04:22:54 GMTServer: Apache Coyote/1.0Connection: close

<?xml version="1.0" encoding="UTF-8"?>

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<soapenv:Body>

<Test>

<Ones>1</Ones>

<Two>three</Two>

</Test>

</soapenv:Body>

</soapenv:Envelope>


JMS/MQ Transport:

JMS/MQ provides MOM based channel for carrying messages. MOM products
offer asynchronous delivery, guaranteed delivery, once only delivery,
persistent messages that can be used for Web Services. The following shows
Web Service implementation using JMS server.

         

In the above framework the Web Service gives the price for the part
requested and the SOAP message is transported using a JMS server like
Weblogic or SonicMQ.

The SOAP Client constructs the message that contains the part ID for
which the price is required. It invokes the AXIS Client that checks the
transport. Since the transport is for JMS the JMSSender gets the message
and puts it in the request Queue. The JMSListener receives the message and
creates an instance of AXIS Server that invokes the corresponding web
service. The web service gives the response that is got by the AXIS
Server. This is placed in the response Queue and the JMS Sender gets the
response that is passed to the SOAP client.

SMTP Transport:

SMTP is very widely used like HTTP and can also be used for carrying SOAP
messages. Some of the advantages are its widespread use, asynchronous, store
and forward. Hence one way messaging and two way using correlation of the
request and response are possible using SMTP for SOAP. For SMTP the binding is
set to http://schemas.pocketsoap.com/soap/smtp

in the WSDL.

To: <soap@example.org>

From: <soap@client.com>

Reply-To: <soap@client.com>

Date: Tue, 15 Nov 2001 23:27:00 -0700

Message-Id: <1F75D4D515C3EC3F34FEAB51237675B5@client.com>

MIME-Version: 1.0

Content-Type: text/xml; charset=utf-8

Content-Transfer-Encoding: QUOTED-PRINTABLE

<?xml version=3D"1.0" encoding=3D"UTF-8"?>

<SOAP-ENV:Envelope SOAP-ENV:encodingStyle=3D"http://schemas.xmlsoap.org/soap/encoding/"

xmlns:SOAP-ENC=3D"http://schemas.xmlsoap.org/soap/encoding/"

xmlns:SOAP-ENV=3D"http://schemas.xmlsoap.org/soap/envelope/"

xmlns:xsd=3D"http://www.w3.org/2001/XMLSchema"

xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance">

<SOAP-ENV:Body>

<m:echoString xmlns:m=3D"http://soapinterop.org/">

<inputString>get your SOAP over SMTP here !</inputString>

</m:echoString>

</SOAP-ENV:Body>

</SOAP-ENV:Envelope>

To: <soap@client.com>

From: <soap@example.org>

Date: Tue, 13 Nov 2001 23:27:00 -0700

In-Reply-To: <1F75D4D515C3EC3F34FEAB51237675B5@client.com>

Message-Id: <FF75D4D515C3EC3F34FEAB51237675B5@soap.example.org>

MIME-Version: 1.0

Content-Type: TEXT/XML; charset=utf-8

Content-Transfer-Encoding: QUOTED-PRINTABLE

<?xml version=3D"1.0" encoding=3D"UTF-8"?>

<SOAP-ENV:Envelope SOAP-ENV:encodingStyle=3D"http://schemas.xmlsoap.org/soap/encoding/"

xmlns:SOAP-ENC=3D"http://schemas.xmlsoap.org/soap/encoding/"

xmlns:SOAP-ENV=3D"http://schemas.xmlsoap.org/soap/envelope/"

xmlns:xsd=3D"http://www.w3.org/2001/XMLSchema"

xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance">

<SOAP-ENV:Body>

<m:echoStringResponse xmlns:m=3D"http://soapinterop.org/">

<return>get your SOAP over SMTP here !</return>

</m:echoStringResponse>

</SOAP-ENV:Body>

</SOAP-ENV:Envelope>

SMTP

This is similar to JMS Transport except that there is a SMTP Handler for
sending mails and a SMTP listener to get the mails at the server end. The following diagram shows framework for using SMTP transport for SOAP
messages.

 

 

 

 

 

 

POP

For POP the receiver polls the server to get all the incoming mails and
processes the requests by calling the Web Service.

References

Reference Path

SOAP http://www.w3.org/TR/SOAP/

WSDL http://www.w3.org/TR/wsdl

UDDI http://www.uddi.org/

AXIS http://ws.apache.org/axis/index.html

WS-Conversation http://dev2dev.bea.com/technologies/webservices/SOAPConversation.jsp

SMTP Binding for SOAP http://www.pocketsoap.com/specs/smtpbinding/

SMTP/SOAP http://www7b.boulder.ibm.com/wsdd/library/techarticles/0212_hygh/hygh.html

JMS/SOAP http://www-106.ibm.com/developerworks/webservices/library/ws-jms/index.html?dwzone=webservices

Abbreviations

Abbreviation Explanation/ Expansion of the abbreviation

SOAP Simple Object Access Protocol

UDDI Universal Description Discovery and Integration

WSDL Web Services Description Language

RPC Remote Procedure Call

JMS Java Messaging Service

MQ IBM MQSeries

HTTP Hyper Text Transmission Protocol

SMTP Simple Mail Transfer Protocol

POP Post Office Protocol

Appendix

Axis Web Services

Axis has four styles of Web Services that can be deployed. These are

  • RPC
  • Document
  • Wrapped
  • Message

RPC: RPC services follow the SOAP RPC and encoding rules. Axis will
serialize the XML in SOAP to Java Objects and also deserialize the Java
objects to XML.

Document/Wrapped: The Document/Wrapped services are similar and both used XML Schema
rather than SOAP encoding for the data. Axis uses Java binding for the XML
data.

The following sample contains a SOAP message with a purchase order

<soap:Envelope xmlns="http://xml.apache.org/axis/wsdd/"

xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">

<soap:Body>

<myNS:PurchaseOrder xmlns:myNS="http://commerce.com/PO">

<item>SK001</item>

<quantity>1</quantity>

<description>Sushi Knife</description>

</myNS:PurchaseOrder>

</soap:Body>

</soap:Envelope>

The schema for this purchase order

<schema targetNamespace="http://commerce.com/PO">

<complexType name="POType">

<sequence>

<element name="item" type="xsd:string"/>

<element name="quantity" type="xsd:int"/>

<element name="description" type="xsd:string"/>

</sequence>

</complexType>

<element name="PurchaseOrder" type="POType"/>

</deployment>

For a document style web service the PurchaseOrder is sent as an object
from the client.

This would be <method>(PurchaseOrder po).

For a wrapped style service the <PurchaseOrder> Element is just a
wrapper for the item,quantity and description. The method would be
<method>(String item,int quantity,String description)

Message: Message style services are used when we want to send XML DOM without turning
into Java objects. Hence the sent and received messages are treated as XML DOM
objects rather than Java Objects.

 

About the Author

Krishnakumar B : Consultant Mindtree Consulting — Bangalore INDIA

Email : b_krishnakumar@mindtree.com

I am a Consultant with Mindtree Consulting based in Bangalore India. I work
on Web Services and J2EE related technologies and am currently involved with
trying to build applications using Web Services.

No Comments so fars

Jump into a conversation

No Comments Yet!

You can be the one to start a conversation.