Friday, March 15, 2019

Web Serices and SOAP

Need of Web Services

At a low level web applications and web services are kinda the same thing. They both operatate over http(s). SOAP is just a well defined version of XML. REST is kinda just HTTP. If you wanted to, you could make a web application look like web services and visa versa.
Web Application :
  • User to Program Interaction
  • Static Integration of Components
  • Monolithic Service
  • Add hoc or Proprietary Protocol


Web Services :
  • Program to Program Interaction
  • Dynamic Integration of Components
  • Service Aggregation (Micro Services)
  • Interoprebility

WSDL - Web Services Description Language


WSDL is an XML format for describing network services as a set of endpoints operating on messages containing either document-oriented or procedure-oriented information. The operations and messages are described abstractly, and then bound to a concrete network protocol and message format to define an endpoint. 

WSDL stands for Web Services Description Language. It is the standard format for describing a web service. WSDL was developed jointly by Microsoft and IBM.
  • WSDL is an XML-based protocol for information exchange in decentralized and distributed environments.
  • WSDL definitions describe how to access a web service and what operations it will perform.
  • WSDL is a language for describing how to interface with XML-based services.
  • WSDL is an integral part of Universal Description, Discovery, and Integration (UDDI), an XML-based worldwide business registry.

Fundamental Properties of WSDL



Definition  :

It is the root element of all WSDL documents. It defines the name of the web service, declares multiple namespaces used throughout the remainder of the document, and contains all the service elements described here.


Data types : 
The data types to be used in the messages are in the form of XML schemas.


Message : 
It is an abstract definition of the data, in the form of a message presented either as an entire document or as arguments to be mapped to a method invocation.


Operation : 
It is the abstract definition of the operation for a message, such as naming a method, message queue, or business process, that will accept and process the message.


Port type :
It is an abstract set of operations mapped to one or more end-points, defining the collection of operations for a binding; the collection of operations, as it is abstract, can be mapped to multiple transports through various bindings.


Binding :
It is the concrete protocol and data formats for the operations and messages defined for a particular port type.


Port : 
It is a combination of a binding and a network address, providing the target address of the service communication.


Service : 
It is a collection of related end-points encompassing the service definitions in the file; the services map the binding to the port and include any extensibility definitions.


Structure of the WSDL Document

<definitions>
   <types>
      definition of types........
   </types>

   <message>
      definition of a message....
   </message>

   <portType>
      <operation>
         definition of a operation.......  
      </operation>
   </portType>

   <binding>
      definition of a binding....
   </binding>

   <service>
      definition of a service....
   </service>
</definitions>

Port Type and Operation Elements


Port Type :

  • Defines web service functionality at abstract level grouping sets of message exchanges into operations. 
  • Contain a set of operations that incorporates input, output and fault messages and parameter order 
  • WSDL supports at least a single input and output message, but permits the declaration of an arbitrary number of faults
  • portType element may have one or more operation elements, each of which defines an RPC- or documentstyle Web service method

Java equivalence: 

portType  : Java interface 
operation : method name


Binding & Service Elements

The <binding> element provides specific details on how a portType operation will actually be transmitted over the wire.
  • The bindings can be made available via multiple transports including HTTP GET, HTTP POST, or SOAP.
  • The bindings provide concrete information on what protocol is being used to transfer portType operations.
  • The bindings provide information where the service is located.
The binding element has two attributes : name and type attribute.
<binding name = "Hello_Binding" type = "tns:Hello_PortType">



The <service> element defines the ports supported by the web service. For each of the supported protocols, there is one port element. The service element is a collection of ports.



Web service clients can learn the following from the service element :
  • where to access the service,
  • through which port to access the web service, and
  • how the communication messages are defined.

The service element includes a documentation element to provide human-readable documentation.

Service Element Example

<service name = "Hello_Service">
<documentation>WSDL File for HelloService</documentation>
<port binding = "tns:Hello_Binding" name = "Hello_Port">
<soap:address
location = "http://www.examples.com/SayHello/">
</port>
</service>

SOAP in HTTP


SOAP request are sent using HTTP protocol. SOAPstands for Simple Object Access protocol. It is XML based used for sending and receiving messages. It is defined with in XML.

SOAP supports both functional oriented and message oriented communication 

SOAP messages are carried as the payload of some other network protocol, for example via HTTP or SMTP (Simple Mail Transfer Protocol) or FTP (File Transfer Protocol) or TCP/IP (Transmission Control Protocol/Internet Protocol),



Functional Oriented Communication in SOAP

A SOAP message is an ordinary XML document containing the following elements −
Envelope − Defines the start and the end of the message. It is a mandatory element.

Header − Contains any optional attributes of the message used in processing the message, either at an intermediary point or at the ultimate end-point. It is an optional element.

Body − Contains the XML data comprising the message being sent. It is a mandatory element.

Fault − An optional Fault element that provides information about errors that occur while processing the message.

SOAP Message Structure

<?xml version = "1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV = "http://www.w3.org/2001/12/soap-envelope" 
   SOAP-ENV:encodingStyle = "http://www.w3.org/2001/12/soap-encoding">

   <SOAP-ENV:Header>
      ...
      ...
   </SOAP-ENV:Header>
   <SOAP-ENV:Body>
      ...
      ...
      <SOAP-ENV:Fault>
         ...
         ...
      </SOAP-ENV:Fault>
      ...
   </SOAP-ENV:Body>
</SOAP_ENV:Envelope>

SOAP Header


The optional Header element offers a flexible framework for specifying additional application-level requirements. For example, the Header element can be used to specify a digital signature for password-protected services. Likewise, it can be used to specify an account number for pay-per-use SOAP services.


SOAP Header Example :

<?xml version = "1.0"?>
<SOAP-ENV:Envelope 
   xmlns:SOAP-ENV = " http://www.w3.org/2001/12/soap-envelope"   
   SOAP-ENV:encodingStyle = " http://www.w3.org/2001/12/soap-encoding">

   <SOAP-ENV:Header>
      <t:Transaction 
         xmlns:t = "http://www.tutorialspoint.com/transaction/" 
         SOAP-ENV:mustUnderstand = "true">5
      </t:Transaction>
   </SOAP-ENV:Header>
   ...
   ...
</SOAP-ENV:Envelope>



SOAP Attachments

SOAP messages may have one or more attachments each Attachment Part object has a MIME header to indicate the type of data it contains. 

A SOAP message with attachment will be stored in a multipart MIME Structure.

  • The SOAP message itself will be stored in the first part of the multipart MIME structure will contain the SOAP envelops.
  • Attachments to the SOAP will be stored in other parts in a multiple MIME structure.
  • The SOAP message will contain reference to the attachments.





No comments:

Post a Comment