Thursday, September 5, 2013

WSDL Introduction


WSDL (Web Services Description Language) Introduction

WSDL is an XML-based language for describing Web services and how to access them.

- WSDL stands for Web Services Description Language
- WSDL is written in XML
- WSDL is an XML document
- WSDL is used to describe Web services
- WSDL is also used to locate Web services
- WSDL is a W3C recommendation

The WSDL Document Structure

A WSDL document describes a web service using these major elements.

<typesA container for data type definitions used by the web service
<message>  A typed definition of the data being communicated
<portType> A set of operations supported by one or more endpoints
<binding> A protocol and data format specification for a particular port type

Structure as follows:
<definitions>
     <types>
           data type definitions........
     </types>

     <message>
           definition of the data being communicated....
     </message>

     <portType>
           set of operations......
     </portType>

     <binding>
           protocol and data format specification....
     </binding>
</definitions>

WSDL - The <portType> Element

The <portType> element defines a web service, the operations that can be performed, and the messages that are involved.

<portType> defines the connection point to a web service.

Operation Types :
The request-response type is the most common operation type, but WSDL defines four types:

One-way :

The service receives a message. The operation therefore has a single input element.

The grammar for a one-way operation is:
<wsdl:definitions .... >
    <wsdl:portType .... > *
         <wsdl:operation name="nmtoken">
               <wsdl:input name="nmtoken"? message="qname"/>
         </wsdl:operation>
    </wsdl:portType >
</wsdl:definitions>

Request-response :

The service receives a message and sends a response.
The operation therefore has one input element, followed by one output element.
To encapsulate errors, an optional fault element can also be specified.

The grammar for a request-response operation is:
<wsdl:definitions .... >
     <wsdl:portType .... > *
         <wsdl:operation name="nmtoken" parameterOrder="nmtokens">
                <wsdl:input name="nmtoken"? message="qname"/>
                <wsdl:output name="nmtoken"? message="qname"/>
                <wsdl:fault name="nmtoken" message="qname"/>*
         </wsdl:operation>
     </wsdl:portType >
</wsdl:definitions>

Solicit-response :

The service sends a message and receives a response.
The operation therefore has one output element, followed by one input element.
To encapsulate errors, an optional fault element can also be specified.

The grammar for a solicit-response operation is:
<wsdl:definitions .... >
    <wsdl:portType .... > *
          <wsdl:operation name="nmtoken" parameterOrder="nmtokens">
               <wsdl:output name="nmtoken"? message="qname"/>
               <wsdl:input name="nmtoken"? message="qname"/>
               <wsdl:fault name="nmtoken" message="qname"/>*
          </wsdl:operation>
    </wsdl:portType >
</wsdl:definitions>

Notification :

The service sends a message. The operation therefore has a single output element.

Following is the grammer for a notification operation:
<wsdl:definitions .... >
     <wsdl:portType .... > *
          <wsdl:operation name="nmtoken">
               <wsdl:output name="nmtoken"? message="qname"/>
           </wsdl:operation>
     </wsdl:portType >
</wsdl:definitions>

WSDL Binding Element

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.

For SOAP protocol, the binding is <soap:binding>, and the transport is SOAP messages on top of HTTP protocol.

* You can specify multiple bindings for a single portType.

The binding element has two attributes
- name attribute : defines the name of the binding
- type attribute : points to the port for the binding

<binding name="Hello_Binding" type="tns:Hello_PortType">

SOAP Binding

This enables you to specify SOAPspecific details, including SOAP headers, SOAP encoding styles, and the SOAPAction HTTP header.

The SOAP extension elements include: 

soap:binding
This element indicates that the binding will be made available via SOAP.

The style attribute indicates the overall style of the SOAP message format.
A style value of rpc specifies an RPC format.

The transport attribute indicates the transport of the SOAP messages.

soap:operation
This element indicates the binding of a specific operation to a specific SOAP implementation.

soap:body
This element enables you to specify the details of the input and output messages.

<binding name="Hello_Binding" type="tns:Hello_PortType">
    <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
            <operation name="sayHello">
                    <soap:operation soapAction="sayHello"/>
                    <input>
                          <soap:body
                                  encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
                                  namespace="urn:examples:helloservice"
                                  use="encoded"/>
                   </input>
                   <output>
                           <soap:body
                                   encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
                                   namespace="urn:examples:helloservice"
                                   use="encoded"/>
                   </output>
           </operation>
</binding>

WSDL Ports Element
A <port> element defines an individual endpoint by specifying a single address for a binding.

Here is the grammer to specify a port:
<wsdl:definitions .... >
    <wsdl:service .... > *
         <wsdl:port name="nmtoken" binding="qname"> *
         <-- extensibility element (1) -->
         </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

* The port element has two attributes :
          - name attribute : provides a unique name among all ports defined within in the enclosing WSDL document.
          - binding attribute : refers to the binding using the linking rules defined by WSDL.

* A port MUST NOT specify more than one address.
* A port MUST NOT specify any binding information other than address information.

<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>

Reference : http://www.w3schools.com

XML - (B) Namespaces


XML Namespaces -

XML Namespaces provide a method to avoid element name conflicts.

Name Conflicts -

In XML, element names are defined by the developer. This often results in a conflict when trying to mix XML documents from different XML applications.

This XML carries HTML table information:
<table>
     <tr>
            <td>Apples</td>
            <td>Bananas</td>
     </tr>
</table>

This XML carries information about a table (a piece of furniture):
<table>
         <name>Coffee Table</name>
</table>
 
If these XML fragments were added together, there would be a name conflict. Both contain a <table> element, but the elements have different content and meaning.
An XML parser will not know how to handle these differences.

Solving the Name Conflict Using a Prefix -

Name conflicts in XML can easily be avoided using a name prefix.

This XML carries information about an HTML table, and a piece of furniture:
<h:table>
      <h:tr>
              <h:td>Apples</h:td>
              <h:td>Bananas</h:td>
      </h:tr>
</h:table>

<f:table>
        <f:name>Coffee Table</f:name>
</f:table>
In the example above, there will be no conflict because the two <table> elements have different names.

The xmlns Attribute

The namespace is defined by the xmlns attribute in the start tag of an element.

namespace declaration syntax → xmlns:prefix="URI"

ex -
<f:table xmlns:f=http://www.sanjeeva.com/furniture>

* When a namespace is defined for an element, all child elements with the same prefix are associated with the same namespace.

* Namespaces can be declared in the elements where they are used or in the XML root element.

ex -
<root xmlns:h="http://www.w3.org/TR/html4/"
        xmlns:f="http://www.sanjeeva.com/furniture">

   <h:table>
       <h:tr>
              <h:td>Apples</h:td>
              <h:td>Bananas</h:td>
         </h:tr>
   </h:table>

   <f:table>
        <f:name>African Coffee Table</f:name>
   </f:table>

</root>

Default Namespaces : Defining a default namespace for an element saves us from using prefixes in all the child elements.

<table xmlns="http://www.w3.org/TR/html4/">
     <tr>
         <td>Apples</td>
         <td>Bananas</td>
     </tr>
</table>

<table xmlns="http://www.sanjeeva.com/furniture">
      <name>African Coffee Table</name>
</table>

Reference : http://www.w3schools.com

XML - (A) Introduction


XML Introduction

XML stands for eXtensible Markup Language.

XML is designed to transport and store data. 
HTML was designed to display data. 

* XML tags are not predefined. You must define your own tags . ( ex : <to>, <from> )
* XML is designed to be self-descriptive
* XML is a W3C Recommendation 

* XML was created to structure, store, and transport information. It is just information wrapped in tags.
<note>
     <to>Sanjeeva</to>
     <from>Sandamali</from>
     <message>Happy Birthday</message>
</note>

* XML Separates Data from HTML
XML data is stored in plain text format. This provides a independent way of storing data. This makes it much easier to create data that can be shared by different applications.
      Due to this;
            - XML Simplifies Data Sharing
            - XML Simplifies Data Transport
            - XML Simplifies Platform Changes
            - XML Makes Your Data More Available
            - XML is Used to Create New Internet Languages ( XHTML, WSDL, WAP, WML, RSS, etc. )

XML Tree Structure

<root>
           <child></child>
           <child>
                      <sub-child></sub-child>
           </child>
</root>

* The terms parent, child, and sibling are used to describe the relationships between elements.
* Parent elements have children.
* Children on the same level are called siblings (brothers or sisters).

Basics :

* XML Element Must Have a Closing Tag.  
          <message></message>

* XML tags are case sensitive. 
          The tag <Letter> is different from the tag <letter>.

* Opening and closing tags must be written with the same case. 
           <Message>This is incorrect</message>

* XML Elements Must be Properly Nested  
           <name><firstname>Sanjeeva</firstname></name>

XML Element -

An XML element is everything from (including) the element's start tag to (including) the element's end tag.

An element can contain:
         - other elements
         - text
         - attributes
         - or a mix of all of the above...

<bookstore>
       <book category="CHILDREN">
               <title>Harry Potter</title>
               <author>J K. Rowling</author>
               <year>2005</year>
               <price>29.99</price>
       </book>
       <book category="WEB">
               <title>Learning XML</title>
               <author>Erik T. Ray</author>
               <year>2003</year>
               <price>39.95</price>
       </book>
</bookstore>

<bookstore> and <book> have element contents, because they contain other elements.

<book> also has an attribute (category="CHILDREN").

<title>, <author>, <year>, and <price> have text content because they contain text.

Reference : http://www.w3schools.com