Social Media

Category Archives for Web Services

Web Services – Example WSDL

A WSDL contract defines the following Web Service information –

  • Web Service Data Type
  • Web Service messages
  • Web Service interfaces
  • Bindings between the messages and the representation of the data
  • Transport details for the web services.

Example

[sourcecode lang=”xml”] <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions name="WSDLExampleApplication"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://glenware.com/webservice/WSDLExampleApplication"
targetNamespace="http://glenware.com/webservice/WSDLExampleApplication"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:errors="http://glenware.com/Errors" >

<wsdl:import location="Errors.wsdl" namespace="http://glenware.com/Errors" />

<wsdl:types>
<xsd:schema>
<xsd:import
namespace="http://glenware.com/webservice/WSDLExampleApplication"
schemaLocation="../schema/WSDLExampleApplication.xsd" />
</xsd:schema>
</wsdl:types>

<wsdl:message name="getMyDetailsRequest">
<wsdl:part name="request" element="tns:getMyDetailsRequest"></wsdl:part>
</wsdl:message>
<wsdl:message name="getMyDetailsResponse">
<wsdl:part name="response" element="tns:getMyDetailsResponse"></wsdl:part>
</wsdl:message>

<wsdl:portType name="WSDLExampleApplicationPort">
<wsdl:operation name="getMyDetails">
<wsdl:input message="tns:getMyDetailsRequest"></wsdl:input>
<wsdl:output message="tns:getMyDetailsResponse"></wsdl:output>
</wsdl:operation>
</wsdl:portType>

<wsdl:binding name="WSDLExampleApplicationBinding" type="tns:WSDLExampleApplicationPort">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="getMyDetails">
<soap:operation
soapAction="http://glenware.com/webservice/WSDLExampleApplication/getMyDetails"
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="WSDLExampleApplication">
<wsdl:port binding="tns:WSDLExampleApplicationBinding" name="WSDLExampleApplicationPort">
<soap:address location="http://localhost:8181/cxf/webservice/WSDLExampleApplication" />
</wsdl:port>
</wsdl:service>

</wsdl:definitions>
[/sourcecode]

This shows the two parts of the wsdl –

  • logical part – contains types(wsdl:types), message(wsdl:message), portType(wsdl:portType) elements. Defines service interface and message exchanged
  • concrete part – binding(wsdl:binding) and service(wsdl:service) elements, transportation type

The datatypes are defined in the external “../schema/WSDLExampleApplication.xsd” – this allows types to be shared amongst wsdl’s. This follows standard schema rules –

> Support for simple types (xsd:string, xsd:int, xsd:long, …)
> Support for complex types –

[sourcecode lang=”xml”] <xsd:complexType name="getMyDetailsRequest">
<xsd:sequence>
<xsd:element name="nameString" type="xsd:string" />
<xsd:element name="count" type="xsd:int" />
</xsd:sequence>
</xsd:complexType>
[/sourcecode]
1 7 8 9