Research on Web Service

Keywords: xml network Java encoding

SOA and Web Service

First, understand the relationship between SOA and Web Service:

* SOA Service Oriented Architecture, a concept for large distributed systems;

* Web service is one of the ways to realize SOA. Not all SOAs are based on Web service.

* But Web service is really the most mainstream way to implement SOA. Some people even equate SOA with Web service. It is undeniable that the success of Web Service has contributed to the success of the concept of SOA.

 

Webservice

Webservice has three basic standards:

1.WSDL Web Service Definition Language (WSDL) is used to define service interfaces. In fact, it can describe two different aspects of a service: the signature (name and parameters) of the service and the binding and deployment details (protocol and location) of the service.

2.SOAP: Simple Object Access Protocol, which defines Web Service. HTTP is an underlying protocol for network data interaction, while SOAP is a special protocol for Web Service data exchange.

UDDI: Universal Description, Discovery and Integration (UDDI), a directory service, can be used by enterprises to register and search for Web services.

SOAP is a protocol, just like HTTP protocol, the general framework has been integrated.

UDDI's complementary role is not necessary and is usually not used in practice.

WSDL is the most interesting thing that developers deal with, and it's also the core of Web Service.
 

WSDL

WSDL now has two major versions, 1.1 and 2.0. The two versions are similar in structure and slightly different. (WSDL version 1.1 root node is definitions, version 2.0 root node is description)

 

 

 

 

WSDL Example

WSDL is usually generated by frameworks, not by hand, as Java can use wsgen  The. Net framework also has its own way to generate web services. It can publish interfaces as WSDL files through its own framework.
A simple example of WSDL. This WSDL file defines a service called CustomerService that provides an operation called getCustomerAdress(). The input parameter for this operation is a customer ID of type long, and the output is a structure containing three string attributes - street, city and zip code. (Examples from the SOA Practice Guide)

<?xml version="1.0" encoding="utf-8" ?>  
<definitions name="CustomerService"  
     targetNamespace="http://soa-in-practice.com/wsdl"  
     xmlns:tns="http://soa-in-practice.com/wsdl"  
     xmlns:xsd1="http://soa-in-practice.com/xsd"  
     xmlns:xsd="http://www.w3.org/2001/XMLSchema"  
     xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"  
     xmlns="http://schemas.xmlsoap.org/wsdl/">  
  
     <types>  
          <xsd:schema  
               targetNamespace="http://soa-in-practice.com/xsd"  
               xmlns="http://soa-in-practice.com/xsd">  
  
               <xsd:element name="getCustomerAddress">  
                    <xsd:complexType>  
                         <xsd:sequence>  
                              <xsd:element name="customerID" type="xsd:long"/>  
                         </xsd:sequence>  
                    </xsd:complexType>  
               </xsd:element>  
  
               <xsd:element name="getCustomerAddressResponse" type="Address"/>  
               <xsd:complexType name="Address">  
                    <xsd:sequence>  
                         <xsd:element name="street" type="xsd:string"/>  
                         <xsd:element name="city" type="xsd:string"/>  
                         <xsd:element name="zipCode" type="xsd:string"/>  
                    </xsd:sequence>  
               </xsd:complexType>  
  
          </xsd:schema>  
     </types>  
  
     <message name="getCustomerAddressInput">  
          <part name="params" element="xsd1:getCustomerAddress"/>  
     </message>  
     <message name="getCustomerAddressOutput">  
          <part name="params" element="xsd1:getCustomerAddressResponse"/>  
     </message>  
  
     <portType name="CustomerInterface" >  
          <operation name="getCustomerAddress">  
               <input message="tns:getCustomerAddressInput" />  
               <output message="tns:getCustomerAddressOutput" />  
          </operation>  
     </portType>  
  
     <binding name="CustomerSOAPBinding"  
          type="tns:CustomerInterface" >  
          <soap:binding style="document"  
          transport="http://schemas.xmlsoap.org/soap/http" />  
          <operation name="getCustomerAddress">  
               <soap:operation  
               soapAction="http://soa-in-practice.com/getCustomerAddress" />  
               <input>  
                    <soap:body use="literal" />  
               </input>  
               <output>  
                    <soap:body use="literal" />  
               </output>  
          </operation>  
     </binding>  
  
     <service name="CustomerService" >  
          <port name="CustomerPort"  
               binding="tns:CustomerSOAPBinding">  
               <soap:address  
               location="http://soa-in-practice.com/customer11"/>  
          </port>  
     </service>  
  
</definitions>

Interpretation of WSDL Files

Reading a WSDL requires looking from the bottom up:

The final < Service > node defines the name of the service as CustomerService, and the service can be found at http://soa-in-practice.com/customer11.

     <service name="CustomerService" >
          <port name="CustomerPort"
               binding="tns:CustomerSOAPBinding">
               <soap:address
               location="http://soa-in-practice.com/customer11"/>
          </port>
     </service>

 

The < binding > node defines the protocols and formats used to provide Web services. Customer SOA Biding is the name of Binding and indicates which interface Binding begins with (here, Customer Interface)

     <binding name="CustomerSOAPBinding"
          type="tns:CustomerInterface" >
          <soap:binding style="document"
          transport="http://schemas.xmlsoap.org/soap/http" />
          <operation name="getCustomerAddress">
               <soap:operation
               soapAction="http://soa-in-practice.com/getCustomerAddress" />
               <input>
                    <soap:body use="literal" />
               </input>
               <output>
                    <soap:body use="literal" />
               </output>
          </operation>
     </binding>

 

PortType describes the CustomerInterface interface, which contains an Operation called getCustomerAddress. Under Operation, getCustomer Address Input and getCustomer Address Output are the input and output messages of the Operation.

     <portType name="CustomerInterface" >
          <operation name="getCustomerAddress">
               <input message="tns:getCustomerAddressInput" />
               <output message="tns:getCustomerAddressOutput" />
          </operation>
     </portType>

 

The < message > node defines each message, using the identifier referenced by the < portType > node.

     <message name="getCustomerAddressInput">
          <part name="params" element="xsd1:getCustomerAddress"/>
     </message>
     <message name="getCustomerAddressOutput">
          <part name="params" element="xsd1:getCustomerAddressResponse"/>
     </message>

 

The < type > node defines the data types to be used: the input parameter customerID is of type long, and the output parameter address is of type structure/record with three string attributes. All types are in their own namespace xsd1.

     <types>
          <xsd:schema
               targetNamespace="http://soa-in-practice.com/xsd"
               xmlns="http://soa-in-practice.com/xsd">

               <xsd:element name="getCustomerAddress">
                    <xsd:complexType>
                         <xsd:sequence>
                              <xsd:element name="customerID" type="xsd:long"/>
                         </xsd:sequence>
                    </xsd:complexType>
               </xsd:element>

               <xsd:element name="getCustomerAddressResponse" type="Address"/>
               <xsd:complexType name="Address">
                    <xsd:sequence>
                         <xsd:element name="street" type="xsd:string"/>
                         <xsd:element name="city" type="xsd:string"/>
                         <xsd:element name="zipCode" type="xsd:string"/>
                    </xsd:sequence>
               </xsd:complexType>

          </xsd:schema>
     </types>

SOAP

SOAP (Simple Object Access Protocol) is a message framework, which is based on XML protocol. As can be seen from the figure below, the framework of SOAP is very similar to HTTP protocol, which contains the Header and Body of messages, but SOAP is a special protocol for Web Service data exchange. SOAP is the upper layer protocol of HTTP, and ultimately data is transmitted through HTTP.

 

SOAP Reqeust Example

<?xml version='1.0' ?>  
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">  
     <soap:Header>  
          ...  
     </soap:Header>  
     <soap:Body>  
          <getCustomerAddress xmlns="http://soa-in-practice.com/xsd">  
               <customerID>12345678</customerID>  
          </getCustomerAddress >  
     </soap:Body>  
</soap:Envelope>

SOAP Response Example

<?xml version='1.0' ?>  
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">  
     <soap:Header>  
          ...  
     </soap:Header>  
     <soap:Body>  
          <getCustomerAddressResponse xmlns="http://soa-in-practice.com/xsd">  
               <address>  
                    <street>Gaussstr. 29</street>  
                    <city>Braunschweig</city>  
                    <zipCode>D-38106</zipCode>  
               </address>  
          </getCustomerAddressResponse>  
     </soap:Body>  
</soap:Envelope> 

The root element of the SOAP message is <Envelope>

As you can see from the above, SOAP is based on XML, and in addition to the organizational structure, it is very similar to HTTP's Request and Response.

 

HTTP Request Example

GET /path/file.html HTTP/1.0  
From: someuser@jmarshall.com  
User-Agent: HTTPTool/1.0  
[blank line here]  

HTTP Response Example

HTTP/1.0 200 OK  
Date: Fri, 31 Dec 1999 23:59:59 GMT  
Content-Type: text/html  
Content-Length: 1354  
  
<html>  
<body>  
<h1>Happy New Millennium!</h1>  
(more file contents)  
  .  
  .  
  .  
</body>  
</html>  

 

Reference material:

SOA Practice Guide

http://wiki.rsg.pml.ac.uk/pywps/WSDL

Posted by jkatcherny on Mon, 01 Jul 2019 12:33:52 -0700