Detailed description of WSDL

Source: Internet
Author: User
Tags abstract definition

A Web Service Description Language (WSDL) is an XML application that defines a web service description as a set of service access points, the client can use these service access points to access services that contain document information or process calls (similar to remote process calls ). WSDL first abstracts the access operations and the request/response messages used for access, then, bind it to the specific transmission protocol and Message format to finally define the service access point for specific deployment. The Service Access Points of specific deployment become abstract web services through combination. This article will explain in detail the structure of the WSDL document and analyze the role of each element. I. Definition of WSDL
WSDL is a document used to accurately describe Web services. It is an XML document that follows the wsdl xml mode. The WSDL document defines a web service as a set of service access points or ports. In WSDL, since the abstract definitions of service access points and messages have been separated from the specific service deployment or data format binding, you can re-use the abstract definition: message, the abstract description of the exchange data, and the port type refers to the abstract set of operations. The specific protocols and data format specifications used for specific port types constitute a reusable binding. Associate the Web access address with the available binding. You can define a port, and the set of ports is defined as a service.
A wsdl document usually contains seven important elements: types, import, message, porttype, operation, binding, and service. These elements are nested in the definitions element, which is the root element of the WSDL document. The next part of this article will detail the basic structure of WSDL.
Ii. Basic Structure of WSDL-Overview
As described at the end of part 1, a basic WSDL document contains seven important elements. The following describes these elements and their functions.
The WSDL document uses the following elements in the Web service definition:

  • Types-a data type-defined container that uses a type system (typically a type system in XML Schema ).
  • Message: an abstract and typed definition of the data structure of a 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 by the Service. Generally, a single operation describes the request/Response Message pair of an access entry.
  • Porttype-an abstract set of operations supported by an access entry point type. These operations can be supported by one or more service access points.
  • Binding-binding of specific protocols and data format specifications for specific port types.
  • Port-defines a single service access point that combines protocol/Data Format binding with a specific web access address.
  • Service-a collection of service access points.

You can refer to the following to understand the structure of the WSDL document:
The XML schema of WSDL can refer to the following url: http://schemas.xmlsoap.org/wsdl/
III. Basic Structure of WSDL-Details
This section uses an example to describe the role of each element in the WSDL document. The following example shows the content of a simple WSDL document. For more information about the generation of this document, see my other article: xfire development instance-helloworld (http://blog.csdn.net/juxtapose/archive/2007/09/10/1779849.aspx ).
A simple Web Service WSDL document that supports the unique operation named sayhello, which is implemented by running the SOAP protocol on HTTP. This request accepts a string name and returns a simple string after processing. The document 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 uses the XML schema language to declare the complex data types and elements used elsewhere in the WSDL document;
? The import element is similar to the import element in the XML schema document. It is used to import the WSDL definition from other WSDL documents;
? The message element describes the message payload by using the built-in types, complex types, or elements defined in the XML schema defined in the type element of the WSDL document or the external WSDL document referenced by the import element;
? The porttype and operation elements describe Web service interfaces and define their methods. The porttype and operation elements are similar to the method declarations defined in Java interfaces and interfaces. The operation element uses one or more message types to define its input and output payload;
? The binding element assigns the porttype and operation elements to a special protocol and encoding style;
? The service element is responsible for assigning the Internet address to a specific binding;
1. Definitions Element
The root element of all WSDL documents is the definitions element. This element encapsulates the entire document and provides a WSDL document through its name. This element has no effect except to provide a namespace, so it is not described in detail.
The following code is a definitions element structure:
<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 adopts the W3C XML Schema built-in type as its basic type system. The types element is used as a container to define various data types not described in the built-in types of the XML mode. When declaring the payload of the message, the message definition uses the data type and element defined in the types element. In the WSDL document of this article, the types definition is as follows:

<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>
The data definition section above defines two elements: sayhello and sayhelloresponse:
Sayhello: defines a complex type that only contains a simple string and will be used to describe the input part of the operation parameters;
Sayhelloresponse: defines a complex type that only contains a simple string and will be used to describe the return value of the operation in the future;
3. Import Element
The import element allows you to use the definition elements in the namespace specified in other WSDL documents in the current WSDL document. The import element is not used in this example. This function is very effective when users want to modularize the 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"/>
The namespace and location attributes must be available:
Namespace attribute: The value must match the targetnamespace declared in the imported WSDL document;
Location attribute: it must point to an actual WSDL document and cannot be empty.
4. Message Element
The message element describes the server load for the Web service to use messages. The message element can describe the load of the output or receive message, and the content of the soap file header and the error detail element. The way to define the message element depends on whether to use the RPC style or the document style for message transmission. In the definition of the message element in this article, this document uses the Document Style message transmission:
<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 part is the abstract definition of Message format: defines two messages: sayhelloresponse and sayhellorequest:
Sayhellorequest: The Request Message format for the sayhello operation. It consists of a message segment named parameters. The element is an element in the types we defined earlier;
Sayhelloresponse: Response Message format of the sayhello operation. It consists of a message segment named parameters. The element is the element in the types we defined earlier;
If RPC-style message transmission is adopted, you only need to change the element in the document to type.
5. porttype Element
The porttype element defines the abstract interfaces of Web Services. This interface is a bit similar to Java interfaces. It defines an abstract type and method and does not define implementation. In WSDL, The porttype element is implemented by the binding and service elements. These two elements are used to describe the Internet protocol, encoding scheme, and Internet address used by the Web Service implementation.
Multiple operations can be defined in one porttype. One operation can be considered as a method. The definition of the WSDL document in this article is as follows:
<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 the service call mode. Here, it contains an operation sayhello method and input and output, indicating that the operation is a request/response mode. The request message is the previously defined sayhellorequest, the response message is the previously defined sayhelloresponse. Input indicates the server load that is passed to the Web service, and output indicates the server load 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 transmission styles, and encoding styles. The binding element is usually used together with the Protocol proprietary element. The example in this article is as follows:
<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>
This Part binds the abstract definition of the Service Access Point with soap HTTP and describes how to access the Access Point deployed according to the access point type described above through soap/HTTP. It specifies that the soapaction to be used in a specific soap call is "".
For specific usage, refer to the elements defined by the specific protocol.
7. Service and port Elements
The service element contains one or more port elements, each of which represents a different web service. The port element assigns a URL to a specific binding, and even two or more port elements assign different URLs to the same binding. Example in the document:
<WSDL: Service name = "helloservice">
<WSDL: Port name = "helloservicehttpport"
Binding = "TNS: helloservicehttpbinding">
<Wsdlsoap: Address
Location = "http: // localhost: 8080/xfire/services/helloservice"/>
</WSDL: Port>
</WSDL: Service>
This part is the definition of a specific web service. In this web service named helloservice, a service access portal is provided. The access address is http: // localhost: 8080/xfire/services/helloservice, the message mode is defined by the previous binding.

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.