This part includes:
Web services have many different forms and let's start with the RPC-style and document-style.We need to provide an operation call "concat" with the following details:
- What is a Web Service (WS) ?
- Simple example to design a WS using RPC-style and document-style.
What is Web Service (WS)?
A Web Service is a public service that's published in the web or the internet.Such a service is required to be accessible from different platforms (Windows,Unix,Linux,Mac OS) and languages (Java, C#, C++, Python,etc.). Such services are supposed to provide their clients with well defined operations that will take some inputs and produce outputs.The communication between peers is detailed in a contract called WSDL or Web Service Description Language.
Let's start with a simple example.We need to create and publish a web service that provides concatenation operation for two input strings.
We will use a web server URL for publishing the web service "http://www.mycompany.com" and our WS at the path "/HelloWorldWS", That support only one operation for now called "concat"
![]() |
Figure 1. |
Local name: concat
Namespace: http://mycompany.com/HelloWorldWS
Input Parameters:
str1: type(String)
str2: type(String)
Output Parameters:
return: type(String)
RPC-Style:
RPC stands for "Remote Procedure Call".A procedure call in WS is called "input message" and every input parameter is called "part".The return value is called "output message" and can also have many parts (XML complex type).So in the case of RPC , our operation is looks like:
Local name: concat
Namespace: http://mycompany.com/HelloWorldWS
Input message:
Part1:
Name: str1
Type: string
Part2:
Name: str2
Type: string
Output message:
Part1:
Name: return
Type: string
So when we send an input message to that WS will be like:
<p:concat xmlns:p="http://mycompany.com/HelloWorldWS">
<str1>abc</str1>
<str2>def</str2>
</p:concat>
And the output message would be like:
<p:concat xmlns:p="http://mycompany.com/HelloWorldWS">
<return>abcdef</return>
</p:concat>
So you will notice that the QName or Qualified Name of the operation and the names of its parts are used in the input and output messages.So it's called RPC-style as it looks that you're calling a method defined by name and its input/output parameters.
QName or (Qualified Name) is the identifier or the full name of an element in XML.Simply it's the local part name + the namespace.
For example: <p:concat xmlns:p="http://mycompany.com/HelloWorldWS">
"p" is the prefix for the namespace "http://mycompany.com/HelloWorldWS" and the local part is "concat".
Document-Style:
Our operation "concat" details is listed below with the document-style:
Local name: concat
Namespace: http://mycompany.com/HelloWorldWS
Input message:
Part1:
Name: concatRequest
Element: concatRequest in http://mycompany.com/HelloWorldWS
Output message:
Part1:
Name: concatResponse
Element:
concatResponse in http://mycompany.com/HelloWorldWS
And we define all input and output parts as complex types in the XML schema as next:
<xsd:schema targetNamespace="http://mycompany.com/HelloWorldWS"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="concatRequest">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="str1" type="xsd:string"/>
<xsd:element name="str2" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="concatResponse" type="xsd:string"/>
</xsd:schema>
The input message would be like:
<p:concatRequest xmlns:p="http://mycompany.com/HelloWorldWS">
<str1>abc</str1>
<str2>def</str2>
</p:concatRequest>
And the output message would be like:
<p:concatResponse xmlns:p="http://mycompany.com/HelloWorldWS">
abcdef
</p:concatResponse>
The difference between RPC-style and document-style:
The significant difference is that the former can't be validated with a schema while the latter can. Therefore, document style web service is becoming the dominant style. According to an organization called "WS-I (web services interoperability organization)", you should use document style web services only.