WSDL, One of the Elements of Web Services

WSDL is one of the elements of Web services. This article introduces WSDL document structure, port, and binding. How to use WSDL? Examples are provided in this article.

1. WSDL Document Structure

The schematic diagram of the WSDL element structure is shown in the following figure.

WSDL Document Structure

1. Type is a container of data type definitions, which contains the type definitions of all XML elements required in the message definition.

2. Message specifically defines the data structure of the message used in communication. The Message element contains a set of Part elements, each of which is a component of the final message. Each Part references a DataType to represent its structure. Part elements do not support nesting.

3. PortType specifically defines a type of service access entry. What is the type of access entry? It is the pattern of incoming/outgoing messages and their format.

A PortType can contain several operations, and an operation refers to a type of invocation supported by the access entry. The above three structures describe the abstract definition of invoking Web services. These three parts have nothing to do with the specific Web service deployment details but are reusable descriptions (each level can be reused).

4. Service describes the deployment details of all access portals provided by a specific deployed Web service. A Service often contains multiple service access entries, and each access entry is described by a Port element.

5. Port describes the deployment details of a service access portal, including which Web address (URL) to access through, what message calling mode should be used to access, etc. The message calling mode is represented by the Binding structure.

6. The Binding structure defines that a PortType is bound to a specific network transmission protocol or message transmission protocol. From this level, the description is related to the deployment of specific services. For example, PortType can be bound to SOAP/HTTP, PortType can also be bound to MIME/SMTP, etc.

WSDL Port

element is the most important WSDL element. It describes the operations that a Web service can perform and the associated messages. An element can be compared to a library (or a module, or a class) in a traditional programming language.

An example of a one-way operation

<message name="newTermValues">
<part name="term" type="xs:string"/>
<part name="value" type="xs:string"/>
</message>
<portType name="glossaryTerms">
<operation name="setTerm">
<input name="newTerm" message="newTermValues"/>
</operation>
</portType>

In this example, the port "glossaryTerms" defines a one-way operation called "setTerm". The "setTerm" operation accepts input of new glossary item messages. These messages use a message named "newTermValues" with input parameters "term" and "value". However, no output is defined for this operation.

An example of a Request-response operation

<message name="getTermRequest">
<part name="term" type="xs:string"/>
</message>
<message name="getTermResponse">
<part name="value" type="xs:string"/>
</message>
<portType name="glossaryTerms">
<operation name="getTerm">
<input message="getTermRequest"/>
<output message="getTermResponse"/>
</operation>
</portType>

In this example, the port "glossaryTerms" defines a request-response operation named "getTerm". The "getTerm" operation requests an input message named "getTermRequest" with a parameter named "term" and will return an output message named "getTermResponse". This message takes a parameter named "value".

WSDL Binding

The following is an example of a binding.

<message name="getTermRequest">
<part name="term" type="xs:string"/>
</message>
<message name="getTermResponse">
<part name="value" type="xs:string"/>
</message>
<portType name="glossaryTerms">
<operation name="getTerm">
<input message="getTermRequest"/>
<output message="getTermResponse"/>
</operation>
</portType>
<binding type="glossaryTerms" name="b1">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" />
<operation>
<soap:operation soapAction="http://example.com/getTerm"/>
<input><soap:body use="literal"/></input>
<output><soap:body use="literal"/></output>
</operation>
</binding>

The binding element has two attributes "name" and "type". The "name" attribute defines the name of the binding, while the "type" attribute points to the binding's port, which in this case is the "glossaryTerms" port.

The soap:binding element has two attributes, "style" and "transport". The "style" attribute can take the value "rpc" or "document".

In this example, we use "document". The "transport" attribute defines the protocol used by SOAP, in this case, HTTP.

The operation element defines the operators provided by each port. For each operation, the corresponding SOAP behavior needs to be defined. You must also know how to encode the input and output. "literal" is used in this example.



Leave a reply



Submit