The WSDL file is a file that defines the information needed so that we can build a SOAP Web Service. In this tutorial, I will show you guys the details about the contents of this WSDL file.
First, let’s take a look at an example about the contents of a WSDL file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
<?xml version="1.0" encoding="UTF-8"?> <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://muleesbcxfsoapexpose.huongdanjava.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="HelloWorldServiceService" targetNamespace="http://muleesbcxfsoapexpose.huongdanjava.com/"> <wsdl:types> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="unqualified" targetNamespace="http://muleesbcxfsoapexpose.huongdanjava.com/" version="1.0"> <xs:element name="hello" type="tns:hello" /> <xs:element name="helloResponse" type="tns:helloResponse" /> <xs:complexType name="hello"> <xs:sequence> <xs:element minOccurs="0" name="arg0" type="xs:string" /> </xs:sequence> </xs:complexType> <xs:complexType name="helloResponse"> <xs:sequence> <xs:element minOccurs="0" name="return" type="xs:string" /> </xs:sequence> </xs:complexType> </xs:schema> </wsdl:types> <wsdl:message name="helloResponse"> <wsdl:part element="tns:helloResponse" name="parameters" /> </wsdl:message> <wsdl:message name="hello"> <wsdl:part element="tns:hello" name="parameters" /> </wsdl:message> <wsdl:portType name="HelloWorldService"> <wsdl:operation name="hello"> <wsdl:input message="tns:hello" name="hello" /> <wsdl:output message="tns:helloResponse" name="helloResponse" /> </wsdl:operation> </wsdl:portType> <wsdl:binding name="HelloWorldServiceServiceSoapBinding" type="tns:HelloWorldService"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" /> <wsdl:operation name="hello"> <soap:operation soapAction="" style="document" /> <wsdl:input name="hello"> <soap:body use="literal" /> </wsdl:input> <wsdl:output name="helloResponse"> <soap:body use="literal" /> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="HelloWorldServiceService"> <wsdl:port binding="tns:HelloWorldServiceServiceSoapBinding" name="HelloWorldServicePort"> <soap:address location="http://localhost:8081/hello" /> </wsdl:port> </wsdl:service> </wsdl:definitions> |
As you can see, a WSDL file is defined starting with a root tag named <definitions> with multiple namespace declarations to be used in the WSDL file. In these namespaces, note the namespace xmlns:soap= “http://schemas.xmlsoap.org/wsdl/soap/”, which is the namespace that defines the SOAP Web Service version.
There are currently two versions of SOAP Web Service:
- In SOAP 1.1, the namespace value will begin with “http://schemas.xmlsoap.org/soap/”.
- For SOAP 1.2, the value will start with “http://www.w3.org/2003/05/soap-envelope”.
Of course, version 1.2 will be better than version 1.1. 😀 But in my example, I am using SOAP version 1.1.
Within the <definitions> tag, you will see the WSDL file defining the following child tags:
The first child tag is <types>, which will contain an XML Schema definition, defines the data types of the SOAP message that the client sends to the Web Service server. Thus, our Web Service can validate the content of the SOAP message according to the definition defined by the WSDL file.
In the above example, I have defined the data types for the <hello> and <helloResponse> tags in the SOAP message.
Next, you will see one or more <message> child tags that define the SOAP messages that our SOAP Web Service will process. You will see that each SOAP message will map to the types of data we have defined in the <types> tag.
Next, you’ll see that it’s a <portType> child tag. In a WSDL file, there is only one <portType> tag, essentially for defining SOAP Web Service interfaces, including operations along with mapping messages. An operation will include the message for the input (client request message) and the message output (response message returned to the client) and the message if the error occurred. These messages will be defined in the <message> tag that I said above.
In the above example, we defined an operation with the input message hello and the output message helloResponse defined in the two <message> tags of the WSDL file.
The near last child tag in the <definitions> tag is the <binding> tag. This tag defines the implementation of our SOAP Web Service, including transport protocol (HTTP), service style and SOAP version. We can define multiple <binding> child tags, depending on the number of transport protocols we want the SOAP Web Service to support.
The last child tag you can see is the <service> child tag. This tag will take all the definitions in the above tags to define a service endpoint, which defines the URL the client will be able to access.
Within this <service> child tag, you can see in the example above that it also defines one or more <port> child tags. With:
1 |
<port> = <portType> + <binding> |
We have only one child <portType> tag, so the number of <port> tags depends on the number of <binding> tags we have defined above.