WSDL File Structure analysis

Source: Internet
Author: User
Tags abstract definition wsdl


The WSDL (Web services Description language,web Service Description Language) is an XML application that defines a Web service description as a set of service access points, These service access points allow clients to access services that contain document-oriented information or process-oriented calls (similar to remote procedure calls). The WSDL first describes the operation that is accessed and the request/Response message used at access, and then binds it to the specific transport protocol and message format to ultimately define the specific deployed service access point. The associated specific deployed service access points become abstract Web services by combining them. This article will explain in detail the structure of the WSDL document and analyze the role of each element.

One: WSDL definition

WSDL is a document that accurately describes a Web service, and the WSDL document is an XML document that follows the WSDL XML schema. A WSDL document defines a Web service as a collection of service access points or ports. In WSDL, because the abstract definition of a service access point and message has been detached from a specific service deployment or data format binding, the abstract definition can be reused: a message, an abstract description of the interchange data, and a port type that refers to an abstract collection of operations. Specific protocols and data format specifications for a specific port type form the bindings that can be reused. The Web Access address is associated with a binding that can be reused, a port can be defined, and a collection of ports is defined as a service.

A WSDL document typically contains 7 important elements, the types, import, message, PortType, operation, binding, and service elements. These elements are nested within the definitions element, and definitions is the root element of the WSDL document. The basic structure of the WSDL is described in detail in the next section of the article.

II: The basic structure of WSDL--Overview

As the first section concludes, a basic WSDL document contains 7 important elements. These elements and their roles are described in the following sections.

The WSDL document uses the following elements in the definition of the Web service:

· Types-a container for a data type definition that uses a type system (generally using the type system in XML schemas).

· Message-Abstract typed definition of the data structure of the communication message. Use the type defined by types to define the data structure of the entire message.

· Operation-an abstract description of the operations supported in the service, typically a single operation describes a request/response message pair for an access portal.

· PortType-an abstract collection of operations supported by an access entry point type that can be supported by one or more service access points.

· Binding-The specific protocol and data format specification bindings for a specific port type.

· Port-Defines a single service access point for which the Protocol/data format binding is combined with a specific Web access address.

· Service-A collection of related service access points.

The XML schema of the WSDL can be referenced by the following URLs: http://schemas.xmlsoap.org/wsdl/

Three: The basic structure of WSDL--details

This section describes in detail the role of each element of a WSDL document through an example. The following example is the content of a simple WSDL document, which can be found in one of my other articles: Xfire Development Example--helloworld.

A simple Web service WSDL document that supports the only operation named SayHello, which is implemented by running the SOAP protocol on HTTP. The request accepts a string name, which is processed to return a simple string. The documentation is as follows:

<?xml version= "1.0" encoding= "UTF-8"?>
<wsdl:definitions
Targetnamespace= "Http://com.liuxiang.xfireDemo/HelloService"
Xmlns:tns= "Http://com.liuxiang.xfireDemo/HelloService"
xmlns:wsdlsoap= "http://schemas.xmlsoap.org/wsdl/soap/"
Xmlns:soap12= "Http://www.w3.org/2003/05/soap-envelope"
Xmlns:xsd= "Http://www.w3.org/2001/XMLSchema"
xmlns:soapenc11= "http://schemas.xmlsoap.org/soap/encoding/"
Xmlns:soapenc12= "Http://www.w3.org/2003/05/soap-encoding"
xmlns:soap11= "http://schemas.xmlsoap.org/soap/envelope/"
Xmlns:wsdl= "http://schemas.xmlsoap.org/wsdl/" >
<wsdl:types>
<xsd:schema xmlns:xsd= "Http://www.w3.org/2001/XMLSchema"
attributeformdefault= "qualified" elementformdefault= "qualified"
Targetnamespace= "Http://com.liuxiang.xfireDemo/HelloService" >
<xsd:element name= "SayHello" >
<xsd:complexType>
<xsd:sequence>
<xsd:element maxoccurs= "1" minoccurs= "1"
Name= "Name" nillable= "true" type= "xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name= "Sayhelloresponse" >
<xsd:complexType>
<xsd:sequence>
<xsd:element maxoccurs= "1" minoccurs= "1"
Name= "Out" nillable= "true" type= "xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
<wsdl:message name= "Sayhelloresponse" >
<wsdl:part name= "Parameters" element= "Tns:sayhelloresponse"/>
</wsdl:message>
<wsdl:message name= "Sayhellorequest" >
<wsdl:part name= "Parameters" element= "Tns:sayhello"/>
</wsdl:message>
<wsdl:porttype name= "Helloserviceporttype" >
<wsdl:operation name= "SayHello" >
<wsdl:input name= "Sayhellorequest"
Message= "Tns:sayhellorequest"/>
<wsdl:output name= "Sayhelloresponse"
Message= "Tns:sayhelloresponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name= "Helloservicehttpbinding"
Type= "Tns:helloserviceporttype" >
<wsdlsoap:binding style= "Document"
transport= "Http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name= "SayHello" >
<wsdlsoap:operation soapaction= ""/>
<wsdl:input name= "Sayhellorequest" >
<wsdlsoap:body use= "literal"/>
</wsdl:input>
<wsdl:output name= "Sayhelloresponse" >
<wsdlsoap:body use= "literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name= "HelloService" >
<wsdl:port name= "Helloservicehttpport"
binding= "Tns:helloservicehttpbinding" >
<wsdlsoap:address
location= "Http://localhost:8080/xfire/services/HelloService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

The ♦types element declares complex data types and elements used in other locations in the WSDL document using the XML Schema language;

The ♦import element is similar to the import element in an XML Schema document and is used to import WSDL definitions from other WSDL documents;

The ♦message element describes the payload of the message using the built-in type, complex type, or element of the XML schema defined in the type element of the WSDL document or in an external WSDL document referenced in the import element;

The ♦porttype element and the operation element describe the interface of the Web service and define his method. The porttype element and the operation element are similar to the method declarations defined in the Java interfaces and interfaces. The operation element uses one or more message types to define the payload of his input and output;

The ♦binding element assigns the porttype element and the operation element to a special protocol and encoding style;

The ♦service element is responsible for assigning an Internet address to a specific binding;

1. Definitions Elements

The root elements of all WSDL documents are definitions elements. The element encapsulates the entire document and provides a WSDL document through its name. In addition to providing a namespace, the element has no other effect and is not described in detail.

The following code is the structure of a definitions element:

<wsdl:definitions
Targetnamespace= "Http://com.liuxiang.xfireDemo/HelloService"
Xmlns:tns= "Http://com.liuxiang.xfireDemo/HelloService"
xmlns:wsdlsoap= "http://schemas.xmlsoap.org/wsdl/soap/"
Xmlns:soap12= "Http://www.w3.org/2003/05/soap-envelope"
Xmlns:xsd= "Http://www.w3.org/2001/XMLSchema"
xmlns:soapenc11= "http://schemas.xmlsoap.org/soap/encoding/"
Xmlns:soapenc12= "Http://www.w3.org/2003/05/soap-encoding"
xmlns:soap11= "http://schemas.xmlsoap.org/soap/envelope/"
Xmlns:wsdl= "http://schemas.xmlsoap.org/wsdl/" >
</wsdl:definitions>

2. Types elements

WSDL uses the built-in XML Schema type as its basic type system. The types element is used as a container for defining various data types that are not described in the XML Schema built-in types. When the payload of the message part is declared, the message definition uses the data types and elements defined in the types element. The types definition in the WSDL document of this article:



<wsdl:types>
<xsd:schema xmlns:xsd= "Http://www.w3.org/2001/XMLSchema"
attributeformdefault= "qualified" elementformdefault= "qualified"
Targetnamespace= "Http://com.liuxiang.xfireDemo/HelloService" >
<xsd:element name= "SayHello" >
<xsd:complexType>
<xsd:sequence>
<xsd:element maxoccurs= "1" minoccurs= "1"
Name= "Name" nillable= "true" type= "xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name= "Sayhelloresponse" >
<xsd:complexType>
<xsd:sequence>
<xsd:element maxoccurs= "1" minoccurs= "1"
Name= "Out" nillable= "true" type= "xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>

Above is the data definition section, which defines two elements, one is SayHello and the other is sayhelloresponse:

SayHello: Defines a complex type that contains only a simple string that will be used in the future to describe the input part of the operation;

Sayhelloresponse: Defines a complex type that contains only a simple string that will be used to describe the return value of the operation;

3. Import Element

The import element allows you to use the definition elements in the namespace specified in the other WSDL document in the current WSDL document. The import element is not used in this example. This feature is often useful when the user wants to modularize a WSDL document.

The import format is as follows:

<wsdl:import namespace= "http://xxx.xxx.xxx/xxx/xxx" location= "http://xxx.xxx.xxx/xxx/xxx.wsdl"/>

You must have the namespace property and the Location property:

Namespace property: The value must match the targetnamespace declared in the WSDL document being imported;

Location property: You must point to an actual WSDL document, and the document cannot be empty.

4. Message element

The message element describes the payload of the Web service using messages. The message element can describe the payload of the output or accept the message, and can also describe the contents of the soap file header and the error detail element. The way you define a message element depends on whether you use RPC style or document-style message delivery. In the definition of the message element in this article, this documentation uses document-style message delivery:

<wsdl:message name= "Sayhelloresponse" >
<wsdl:part name= "Parameters" element= "Tns:sayhelloresponse"/>
</wsdl:message>
<wsdl:message name= "Sayhellorequest" >
<wsdl:part name= "Parameters" element= "Tns:sayhello"/>
</wsdl:message>

This section is an abstract definition of the message format: Two messages sayhelloresponse and sayhellorequest are defined:

The request message format of the Sayhellorequest:sayhello operation consists of a message fragment with the name parameters, and the element is the element in the types we defined earlier;

The response message format of the Sayhelloresponse:sayhello operation, consisting of a message fragment with the name parameters, is the element in the types we defined earlier;

If you are using RPC-style messaging, you only need to modify the element elements in the document to type.

5. PortType elements

The porttype element defines the abstract interface for a Web service. The interface is a bit like the Java interface, which defines an abstract type and method, without defining the implementation. In WSDL, the porttype element is implemented by binding and service elements, which are two elements used to describe the Internet Protocol, encoding scheme, and Internet address used by the Web service implementation.

A porttype can define multiple operation, a operation can be seen as a method, as defined in the WSDL document in this article:

<wsdl:porttype name= "Helloserviceporttype" >
<wsdl:operation name= "SayHello" >
<wsdl:input name= "Sayhellorequest"
Message= "Tns:sayhellorequest"/>
<wsdl:output name= "Sayhelloresponse"
Message= "Tns:sayhelloresponse"/>
</wsdl:operation>
</wsdl:portType>

PortType defines the type of invocation pattern for a service, which contains an action SayHello method that contains input and output indicating that the operation is a request/response pattern, and that the request message is the Sayhellorequest defined earlier, The response message is the previously defined sayhelloresponse. Input represents the payload that is passed to the Web service, and the output message represents the payload that is passed to the customer.

6. Binding

The binding element maps an abstract porttype to a set of specific protocols (SOAO and HTTP), message delivery styles, encoding styles. Usually the binding elements are used in conjunction with protocol-specific elements and examples in this article:

<wsdl:binding name= "Helloservicehttpbinding"
Type= "Tns:helloserviceporttype" >
<wsdlsoap:binding style= "Document"
transport= "Http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name= "SayHello" >
<wsdlsoap:operation soapaction= ""/>
<wsdl:input name= "Sayhellorequest" >
<wsdlsoap:body use= "literal"/>
</wsdl:input>
<wsdl:output name= "Sayhelloresponse" >
<wsdlsoap:body use= "literal"/>
</wsdl:output>
</

WSDL File Structure analysis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.