This article will move through basics of Web Services, the various Web Services platform elements SOAP(Simple Object Access Protocol), UDDI(Universal Description, Discovery and Integration) and WSDL( Web Services Description Language).
What is Web Services?
Web Services is a platform to build loosely coupled applications. A web service is piece of code that can be remotely invoked using HTTP, that means a HTTP request is enough to invoke a web service. Moving back to past remote access to binary data has been either platform specific or vendor specific. For Example
- Microsoft's DCOM( Distributed Component Object Model) for communication among networked computers access remote COM(Component Object Model) interface through remote procedure calls.
- Corba uses IIOP(Internet Inter-ORB Protocol) to access remote objects.
- In Java RMI(Remote Method Invocation) is used to access a EJB(Enterprise Java Bean) object which is again language specific.
All the above example suggests that remotely accessing an object required proprietary technologies which were tightly coupled to the remote code.
Web Services is basically a platform to built a distributed architecture where there are numerous computers connected to each other in a network. The various computers in the network will be running applications developed using different tools, different technologies from different vendors. Each of these applications can be exposed as a Web Service using SOAP, UDDI and WSDL wherein a service running on one computer can access a service running on other irrespective of difference in technologies. So if there is a .Net application running on one computer it can be accessed using a Java application running on other, only condition is both should be exposed as a web service. Web Service clients can be console based as well as browser based.
Why Web Services?
There are several reason why Web Services has become a need
- One of the biggest reason why we need web services is interoperability wherein different Vendor specific applications can interact with each other. For Example a .Net application accessing a Java web service.
- Using Web Services you can expose your application and its functionality globally.
- Using Web Services an enterprise need not depend on one particular vendor for all the solutions. It can move to different vendors for different functionality and can optimally choose out of several options.
- Web Services used standardized protocols SOAP, UDDI, WSDL and HTTP for implementation.
- Web Services has support for most of the communication protocol and it can be implemented using FTP as well as HTTP.
- Web Services follow a loosely coupled architecture.
Web Services Architecture
As can be seen from the architecture diagram the Web Service Provider registers the Web Service to UDDI registry and provides WSDL for invoking service. The Web Service consumer which can be an application client or any other Web Service queries the UDDI registry and finds WSDL. Next the consumer uses WSDL to invoke the SOAP service.
Web Services Description Language(WSDL)
WSDL is a XML way of describing a Web Service. It specifies the location of Web Service and methods available with the service. WSDL is basically a document written in XML. A WSDL document has <portType>, <message>, <types > and <binding> as the elements.
The typical syntax of a WSDL document is as shown below
<definitions> <types> definition of types.... </types> <message> definition of message.... </message> <portType> definition of portType.... </portType> <binding> definition of binding.... </binding> <service> definition of service.... </service> </definitions>
The syntax of a WSDL suggests that it is a set of definitions where the definition element is at the root.
Let us try to understand each element in a WSDL document using a HelloWorld.wsdl document. This is wsdl document which is automatically generated by Geronimo Eclipse Plugin(GEP). In the tutorials section we will learn how to generate it using Eclipse and GEP.
<code:title=HelloWorld.wsdl|borderStyle=solid}
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://webservices" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://webservices" xmlns:intf="http://webservices" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)-->
<wsdl:types>
<schema elementFormDefault="qualified" targetNamespace="http://webservices" xmlns="http://www.w3.org/2001/XMLSchema">
<element name="hello">
<complexType/>
</element>
<element name="helloResponse">
<complexType/>
</element>
</schema>
</wsdl:types>
<wsdl:message name="helloRequest">
<wsdl:part element="intf:hello" name="parameters"/>
</wsdl:message>
<wsdl:message name="helloResponse">
<wsdl:part element="intf:helloResponse" name="parameters"/>
</wsdl:message>
<wsdl:portType name="HelloWorld">
<wsdl:operation name="hello">
<wsdl:input message="intf:helloRequest" name="helloRequest"/>
<wsdl:output message="intf:helloResponse" name="helloResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="HelloWorldSoapBinding" type="intf:HelloWorld">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="hello">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="helloRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="helloResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="HelloWorldService">
<wsdl:port binding="intf:HelloWorldSoapBinding" name="HelloWorld">
<wsdlsoap:address location="http://localhost:8080/SimpleWeb/services/HelloWorld"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
- <types>- Web Service is all about sending and receiving messages. The <types> element describes the various messages which will be used by the service. Basically it defines the various data types. As can be seen HelloWorld service uses hello and helloResponse as the two messages.
- <message>- This element defines the various messages used by the web service. In our example we have two message name, helloRequest which is associated with hello data type and helloResponse which is associated with helloResponse data type as defined in the <types> element. Each message type has unique name which is suggested by <message name=""> tag. The <part element="" ...> suggests the data type associated with each message. <part> element can be considered as a parameter to a function call.
- <portType>- This basically involves a set of operation and messages involved in each operation. <portType name=""> defines a unique name. In our example <wsdl:portType name="HelloWorld"> suggest a unique name. Each portType has an associated <operation name=""> element which suggest an operation name. In our example <wsdl:operation name="hello"> suggests an operation name. Each operation element can have <input>, <output> or both the tags accordingly it will be one-way, notification or request-response operation. Our example has <wsdl:input message="intf:helloRequest" name="helloRequest"/> which uses the helloRequest as the input message and <wsdl:output message="intf:helloResponse" name="helloResponse"/> which uses the helloResponse as the output message.
- <bindings>-