WSDL: Describe your Web Service

Source: Internet
Author: User
Tags abstract definition

August 01, 2001

This article first introduces the WSDL specification that plays a key role in Web Service real-time assembly and automatic integration in Web Service 'stack'. It first introduces the role and significance of WSDL, secondly, it gives a brief introduction to the structure of the WSDL document, discusses the role of each element, and analyzes its open and reusable system design ideas, finally, an instance is used to illustrate the working mode of WSDL.

The resources referenced in this article mainly fall into two categories: Web Service technical resource websites, which contain a large amount of Web Service technical information, and Web Service "stack" technical specifications, they are an overall technical system, including UDDI, SOAP, WSDL, and XML. The links to these resources are provided at the end of this Article. Interested readers can find the desired content through these resource links.

Web Service "stack"

In my previousArticle, I have already introduced the entire Web Service Technical System Web Service "stack", such:

Figure 1. Web Service "stack"

Among them, the green part is a previously defined and widely used transport layer and network layer standard: IP, HTTP, SMTP, and so on. The blue part is the standard protocols for Web Services currently developed, including the service call protocol soap, the Service Description Protocol WSDL, the Service Discovery/Integration Protocol UDDI, and the Service Workflow Description Language WSFL. The orange part describes the higher-level protocols to be developed, such as routing, reliability, and transactions. The yellow part is the common mechanism of each protocol layer. These mechanisms are generally completed by external orthogonal mechanisms.

Among them, a usable web service should select a number of layers of functions as needed, without all the features. However, no matter how to implement a general web service, it has the basic features of Web Services: cross-platform calls and interfaces that can be recognized by machines, you must use WSDL and soap. Soap is used to call web services, while WSDL is used to describe how to use soap to call Web Services.

WSDL is an XML application that defines the 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.

In specific use, we can extend the WSDL (similar to the scalability of soap), regardless of the Message format or network protocol used for communication, you can describe the Service Access Point and the message format used. In the WSDL framework, any message format and network protocol can be used, just as any network protocol can be used in soap. The WSDL Specification defines how to use the SOAP message format, http get/post message format, and MIME format to complete Web service interaction.



Back to Top

WSDL Overview

Since the communication protocols and message formats have been standardized in the Web technology circle, we know that in the general development process, the interface of the object must have the corresponding SDK Description document, web services are also an object, but they are deployed on the web. Naturally, we also need an SDK Description document for the Web service interface. However, the two are different. At present, web applications fully accept the XML standard. Basically, all new technologies are based on the XML standard, secondly, the goal of Web Services is instant assembly, loose coupling, and automatic integration. This means that the SDK Description document should be capable of being recognized by machines.

That is to say, for Web services that use standardized message formats/communication protocols, it needs to describe the call/communication of Web Services in a structured way (that is, XML, it is also very important to achieve this, which is the basic guarantee for real-time web service assembly. WSDL is such a description language. WSDL defines a set of XML-based syntaxes that describe Web Services as a set of service access points that can exchange messages, thus meeting this requirement. The WSDL service is defined as a machine-recognized SDK document provided by the distributed system and can be used to describe automatic application execution.ProgramCommunication details.

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. Therefore, the WSDL document uses the following elements in the Web service definition:

    • Types-A data type-defined container that uses a type system (generally the type system in XML Schema ).
    • Message-Abstract and typed definitions of the data structure of communication messages. Use the type defined by types to define the data structure of the entire message.
    • Operation-Abstract description of the operations supported in the service. Generally, a single operation describes the request/Response Message pair of an access portal.
    • Porttype-For 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-It is defined as 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:

Figure 2. Object Structure of the WSDL Element

Among them, types is a data type definition container that contains all the types of XML elements required in the message definition, I will explain in detail how to define the type in future articles by combining XML schema.

Message specifically defines the data structure of the message used in communication. The message element contains a group of part elements, and each part element is an integral part of the final message, each part references a ype to represent its structure. The part element does not support nesting (datatype can be used to fulfill this requirement.

Porttype defines a type of service access entry. What is the type of access entry? The mode and format of the incoming/outgoing message. A porttype can contain several operations, while an operation is a type of call supported by the access portal. In WSDL, four access entry call modes are supported:

    1. Single request;
    2. Single response;
    3. Request/response;
    4. Response/request.

Requests refer to requests from the client to the Web server, and responses refer to requests from the Web server to the client. One or two messages in the message definition section are referenced in the porttype definition as the format of the request or response message. For example, an access entry to a stock query may support two types of request messages.CodeIn another request message, the name of the stock is specified, and the response message may be the stock price.

The above three structures describe the abstract definition of calling Web services. These three parts are reusable and independent from the details of specific Web Service deployment (each layer can be reused ). Compared with the general object language, this part can be called the object described by IDL, which describes the interface standard of the object, but in the end what language the object is implemented, the detailed specifications of the platform to be followed and the machines to be deployed are described by the following elements.

A Service describes the deployment details of all access portals provided by a specific deployed Web Service. A service usually contains multiple access endpoints, each access entry uses a port element for description.

Port describes the deployment details of a service access portal, including the web address (URL) used for access and the message call mode used for access. The message call mode is represented by the binding structure.

The binding structure defines that a porttype is bound to a specific network transmission protocol or message transmission protocol. At this level, the content described is related to the deployment of a specific service. For example, you can bind porttype to soap/HTTP or mime/SMTP.

After introducing the main elements of WSDL, we will find that the design concept of WSDL fully inherits the consistent design concept of XML-based contemporary web technology standards: openness. WSDL allows you to use other types of definition languages (not just XML Schema) by extension, and supports multiple network transmission protocols and message formats (not just those defined in specifications: SOAP/HTTP, HTTP-GET/post and mime ). At the same time, WSDL also applies the reuse concept in contemporary software engineering and separates the abstract definition layer and the specific deployment layer, greatly increasing the reusability of the abstract definition layer. For example, we can use the abstract definition layer to define an abstract type of web service (for example, the abstract definition of UDDI registry must be completely consistent with the UDDI Specification ), different Operating companies can use different deployment layer descriptions and abstract definitions to describe their own Web Services.



Back to Top

WSDL document example

The following example shows the WSDL definition of a simple web service that provides stock quotations. The Service supports a single operation named getlasttradeprice, which is implemented by running the soap 1.1 protocol over HTTP. This request accepts a tickersymbol of the string type and returns the price of the floating point type.

<? XML version = "1.0"?> <Definitions name = "stockquote" targetnamespace = "http://example.com/stockquote.wsdl" xmlns: TNS = "http://example.com/stockquote.wsdl" xmlns: xsd1 = "http://example.com/stockquote.xsd" xmlns: soap = "http://schemas.xmlsoap.org/wsdl/soap/" xmlns = "http://schemas.xmlsoap.org/wsdl/"> <types> <schema targetnamespace = "http://example.com/stockquote.xsd" xmlns = "http://www.w3.org/1999/XMLSchema"> <element name = "tradepricerequest"> <complextype> <all> <element name = "tickersymbol" type = "string"/> </All> </complextype> </element> <element name = "tradepriceresult"> <complextype> <all> <element name = "price" type = "float"/> </All> </complextype> </element> </Schema> </types>

The above section defines the data type, and defines the structure of two elements:

    • Tradepricerequest (transaction price request): defines this element as a composite type element that contains a string element (tickersymbol.
    • Tradepriceresult: defines this element as a composite type element that contains a floating point value (price.
<Message name = "getlasttradepriceinput"> <part name = "body" element = "xsd1: tradepricerequest "/> </message> <message name =" getlasttradepriceoutput "> <part name =" body "element =" xsd1: tradepriceresult "/> </message>

This part is an abstract definition of the message format, which defines two message formats:

    • Getlasttradepriceinput (Request Message format for obtaining the final transaction price): It is composed of a message segment. The message segment name is body and the specific element type is tradepricerequest. (Previously defined)
    • Getlasttradepriceoutput (Response Message format for obtaining the final transaction price): a message segment is composed of a message segment named "body". The specific element type is tradepriceresult. (Previously defined)
<Porttype name = "stockquoteporttype"> <operation name = "getlasttradeprice"> <input message = "TNS: getlasttradepriceinput"/> <Output Message = "TNS: getlasttradepriceoutput "/> </Operation> </porttype>

This part defines the call mode type of the Service Access Point, indicating that a certain entry type of stockquoteservice is request/response mode, the request message is getlasttradepriceinput, and the response message is getlasttradepriceoutput.

<Binding name = "stockquotesoapbinding" type = "TNS: stockquoteporttype"> <soap: binding style = "document" Transport = "http://schemas.xmlsoap.org/soap/http"/> <operation name = "getlasttradeprice"> <soap: Operation soapaction = "http://example.com/GetLastTradePrice"/> <input> <soap: body use = "literal" namespace = "http://example.com/stockquote.xsd" encodingstyle = "http://schemas.xmlsoap.org/soap/encoding/"/> </input> <output> <soap: body use = "literal" namespace = "http://example.com/stockquote.xsd" encodingstyle = "http://schemas.xmlsoap.org/soap/encoding/"/> </output> </soap: Operation> </soap: binding> </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 in a specific soap call, the soapaction should be used is "http://example.com/GetLastTradePrice", and the request/response message encoding style should adopt the SOAP specification default definition of the encoding style "http://schemas.xmlsoap.org/soap/encoding ".

<Service name = "stockquoteservice"> <documentation> stock query service </documentation> <port name = "stockquoteport" binding = "TNS: stockquotebinding"> <soap: address location = "http://example.com/stockquote"/> </port> </service> </Definitions>

This part is the definition of a specific web service, in this web service called stockquoteservice, provides a service access portal, the access address is "http://example.com/stockquote ", the message mode is defined by the previous binding.

According to the description in this WSDL document, in the use of specific Web Services, the specific soap interaction may be shown below:

SOAP message request:

Post/stockquote HTTP/1.1 HOST: example.com Content-Type: text/XML; charset = "UTF-8" Content-Length: NNNN soapaction: "http://example.com/GetLastTradePrice" <SOAP-ENV: envelope xmlns: SOAP-ENV = "http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV: encodingstyle = "http://schemas.xmlsoap.org/soap/encoding/"> <SOAP-ENV: Body> <m: tradepricerequest xmlns: M = "http://example.com/stockquote.xsd"> <tickersymbol> MSFT </tickersymbol> </M: tradepricerequest> </SOAP-ENV: Body> </SOAP-ENV: envelope>

SOAP message response:

HTTP/1.1 200 OK Content-Type: text/XML; charset = "UTF-8" Content-Length: NNNN <SOAP-ENV: envelope xmlns: SOAP-ENV = "http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV: encodingstyle = "http://schemas.xmlsoap.org/soap/encoding/"/> <SOAP-ENV: Body> <m: tradepriceresult xmlns: M = "http://example.com/stockquote.xsd"> <price> 74.5 </price> </m: tradepriceresult> </SOAP-ENV: Body> </SOAP-ENV: envelope>

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.