We are creaeting this web service from Top-Down approach. That means we are creating the WSDL first and then create the web service using that.

Understanding a WSDL:
There are main 6 sections in a WSDL.

  • wsdl:definitions
  • wsdl:service
  • wsdl:binding
  • wsdl:portType
  • wsdl:message
  • wsdl:types

wsdl:service

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

Web service clients can learn the following from the service element:

  1. where to access the service,
  2. through which port to access the web service, and
  3. how the communication messages are defined.

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

eg :

	<wsdl:service name="GradeThreeMath">
		<wsdl:port name="GradeThreeMathPort" binding="tns:GradeThreeMathBinding">
			<soap:address location="http://localhost:8081/axis2/services/GradeThreeMath" />
		</wsdl:port>
	</wsdl:service>

The binding attributes of port element associate the address of the service with a binding element defined in the web service.

wsdl:binding

The 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 , 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 and type attribute. The name attribute defines the name of the binding, and the type attribute points to the port for the binding, in this case the “tns:Hello_PortType” port.

SOAP Binding

WSDL 1.1 includes built-in extensions for SOAP 1.1. It allows you to specify SOAP specific details including SOAP headers, SOAP encoding styles, and the SOAPAction HTTP header. The SOAP extension elements include the following:

  • soap:binding
  • soap:operation
  • soap:body

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. Normally we are using document in this case.

The transport attribute indicates the transport of the SOAP messages. The value http://schemas.xmlsoap.org/soap/http indicates the SOAP HTTP transport, whereas http://schemas.xmlsoap.org/soap/smtp indicates the SOAP SMTP transport.

soap:operation

This element indicates the binding of a specific operation to a specific SOAP implementation. The soapAction attribute specifies that the SOAPAction HTTP header be used for identifying the service.

soap:body

This element enables you to specify the details of the input and output messages. Here, the body element specifies the SOAP encoding style and the namespace URN associated with the specified service. We are using the literal as use to include XML as is.

eg :

	<wsdl:binding name="GradeThreeMathBinding" type="tns:GradeThreeMathPortType">

		<!-- Use document style and not rpc -->
		<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />

		<!-- Use 'literal' to include OTA XML as-is -->
		<wsdl:operation name="Addition">
			<soap:operation soapAction="Addition" style="document" />
			<wsdl:input>
				<soap:body use="literal" />
			</wsdl:input>
			<wsdl:output>
				<soap:body use="literal" />
			</wsdl:output>
		</wsdl:operation>

		<wsdl:operation name="Devision">
			<soap:operation soapAction="Devision" style="document" />
			<wsdl:input>
				<soap:body use="literal" />
			</wsdl:input>
			<wsdl:output>
				<soap:body use="literal" />
			</wsdl:output>
		</wsdl:operation>

	</wsdl:binding>

wsdl:portType

The element combines multiple message elements to form a complete one-way or round-trip operation.

For example, a can combine one request and one response message into a single request/response operation. This is most commonly used in SOAP services. A portType can define multiple operations.

eg :

	<wsdl:portType name="GradeThreeMathPortType">

		<wsdl:operation name="Addition">
			<wsdl:input message="tns:AdditionRequest" />
			<wsdl:output message="tns:AdditionResponse" />
		</wsdl:operation>

		<wsdl:operation name="Devision">
			<wsdl:input message="tns:DevisionRequest" />
			<wsdl:output message="tns:DevisionResponse" />
		</wsdl:operation>

	</wsdl:portType>

The portType element defines two operations, called Addition and Devision.

The Addition operation consists of a single input message AdditionRequest and an output message AdditionResponse.

Patterns of Operation

WSDL supports four basic patterns of operation:

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

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.

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.

Notification
The service sends a message. The operation therefore has a single outputelement.

wsdl:message

The element describes the data being exchanged between the web service providers and the consumers.

Each Web Service has two messages: input and output.

The input describes the parameters for the web service and the output describes the return data from the web service.

Each message contains zero or more parameters, one for each parameter of the web service function.

Each parameter associates with a concrete type defined in the container element.

eg : In Our Service, there are four messages as follows.

	<wsdl:message name="AdditionRequest">
		<wsdl:part name="AdditionRQ" element="tns:AdditionRequest" />
	</wsdl:message>
	
	<wsdl:message name="AdditionResponse">
		<wsdl:part name="AdditionRS" element="tns:AdditionResponse" />
	</wsdl:message>

	<wsdl:message name="DevisionRequest">
		<wsdl:part name="DevisionRQ" element="tns:DevisionRequest" />
	</wsdl:message>
	
	<wsdl:message name="DevisionResponse">
		<wsdl:part name="DevisionRS" element="tns:DevisionResponse" />
	</wsdl:message>

wsdl:types

A web service needs to define its inputs and outputs and how they are mapped into and out of the services. WSDL element takes care of defining the data types that are used by the web service. Types are XML documents, or document parts.

– The types element describes all the data types used between the client and the server.
– WSDL is not tied exclusively to a specific typing system.
– WSDL uses the W3C XML Schema specification as its default choice to define data types.
– If the service uses only XML Schema built-in simple types, such as strings and integers, then types element is not required.
– WSDL allows the types to be defined in separate elements so that the types are reusable with multiple web services.

Types can be mentioned within the WSDL as follows

<types>
   <schema targetNamespace="http://example.com/stockquote.xsd" xmlns="http://www.w3.org/2000/10/XMLSchema">
			
      <element name="TradePrice">
         <complexType>
            <all>
               <element name="price" type="float"/>
            </all>
         </complexType>
      </element>
		
   </schema>
</types>

or can be imported via a XSD as follows.

	<wsdl:types>
		<xs:schema>
			<xs:import namespace="http://tempuri.org/" schemaLocation="xsd/Math.xsd" />
		</xs:schema>
	</wsdl:types>

 

wsdl:definitions

The element must be the root element of all WSDL documents. It defines the name of the web service.

<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
 xmlns:tns="http://tempuri.org/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
 xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:xs="http://www.w3.org/2001/XMLSchema"
 targetNamespace="http://tempuri.org/" name="GradeThreeMathService">

From the above example, we can conclude that definitions:

– is a container of all the other elements.
– specifies the name of the service. eg : MathService.
– specifies multiple namespaces such as targetNamespace attribute which is a convention of XML Schema that enables the WSDL document to refer to itself, default namespace that all elements without a namespace prefix, (such as message or portType), are therefore assumed to be a part of this and many custome namespaces.

NOTE: The namespace specification does not require the document to be present at the given location. The important point is that you specify a value that is unique, different from all other namespaces that are defined.

Based on the above information we have created a WSDL (GradeThreeMath.wsdl) as follows using the below mentioned XSD (Math.xsd).

GradeThreeMath.wsdl :

<?xml version="1.0" encoding="UTF-8"?>

<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://tempuri.org/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://tempuri.org/" name="GradeThreeMathService">

	<wsdl:types>
		<xs:schema>
			<xs:import namespace="http://tempuri.org/" schemaLocation="xsd/Math.xsd" />
		</xs:schema>
	</wsdl:types>




	<!-- Define request and response messages -->
	
	<wsdl:message name="AdditionRequest">
		<wsdl:part name="AdditionRQ" element="tns:AdditionRequest" />
	</wsdl:message>
	
	<wsdl:message name="AdditionResponse">
		<wsdl:part name="AdditionRS" element="tns:AdditionResponse" />
	</wsdl:message>

	<wsdl:message name="DevisionRequest">
		<wsdl:part name="DevisionRQ" element="tns:DevisionRequest" />
	</wsdl:message>
	
	<wsdl:message name="DevisionResponse">
		<wsdl:part name="DevisionRS" element="tns:DevisionResponse" />
	</wsdl:message>




	<!-- Define operation and reference messages -->

	<wsdl:portType name="GradeThreeMathPortType">

		<wsdl:operation name="Addition">
			<wsdl:input message="tns:AdditionRequest" />
			<wsdl:output message="tns:AdditionResponse" />
		</wsdl:operation>

		<wsdl:operation name="Devision">
			<wsdl:input message="tns:DevisionRequest" />
			<wsdl:output message="tns:DevisionResponse" />
		</wsdl:operation>

	</wsdl:portType>


	<!-- Define SOAP binding -->

	<wsdl:binding name="GradeThreeMathBinding" type="tns:GradeThreeMathPortType">

		<!-- Use document style and not rpc -->
		<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />

		<!-- Use 'literal' to include OTA XML as-is -->
		<wsdl:operation name="Addition">
			<soap:operation soapAction="Addition" style="document" />
			<wsdl:input>
				<soap:body use="literal" />
			</wsdl:input>
			<wsdl:output>
				<soap:body use="literal" />
			</wsdl:output>
		</wsdl:operation>

		<wsdl:operation name="Devision">
			<soap:operation soapAction="Devision" style="document" />
			<wsdl:input>
				<soap:body use="literal" />
			</wsdl:input>
			<wsdl:output>
				<soap:body use="literal" />
			</wsdl:output>
		</wsdl:operation>

	</wsdl:binding>

	<wsdl:service name="GradeThreeMath">
		<wsdl:port name="GradeThreeMathPort" binding="tns:GradeThreeMathBinding">
			<soap:address location="http://localhost:8081/axis2/services/GradeThreeMath" />
		</wsdl:port>
	</wsdl:service>
</wsdl:definitions>

Math.xsd :

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns="http://tempuri.org/" targetNamespace="http://tempuri.org/" elementFormDefault="qualified" version="1.0" id="MathRQ">
	
	<xs:element name="AdditionRequest">
		<xs:complexType>
			<xs:sequence>
				<xs:element name="operand1" type="xs:int" />
				<xs:element name="operand2" type="xs:int" />
				<!-- <xs:element name="decimalPlaces" type="xs:int" /> -->
			</xs:sequence>
		</xs:complexType>
	</xs:element>

	<xs:element name="AdditionResponse">
		<xs:complexType>
			<xs:sequence>
				<xs:element name="result" type="xs:double" />
				<xs:element name="remarks" type="xs:string" />
			</xs:sequence>
		</xs:complexType>
	</xs:element>

	<xs:element name="DevisionRequest">
		<xs:complexType>
			<xs:sequence>
				<xs:element name="operand1" type="xs:int" />
				<xs:element name="operand2" type="xs:int" />
				<!-- <xs:element name="decimalPlaces" type="xs:int" /> -->
			</xs:sequence>
		</xs:complexType>
	</xs:element>

	<xs:element name="DevisionResponse">
		<xs:complexType>
			<xs:sequence>
				<xs:element name="result" type="xs:double" />
				<xs:element name="remarks" type="xs:string" />
			</xs:sequence>
		</xs:complexType>
	</xs:element>
	
</xs:schema>
Advertisements