Detailed explanation of WSDL in WebService

Detailed explanation of WSDL in WebService
When someone develops WebService, especially when there is an interface with a third party, they use the SOAP protocol, and then the user (or background) gives you a WSDL file (or URL) and says to adapt according to the above. At this time, it is necessary to have a certain understanding of WSDL of WebService. This article will summarize WSDL (WebService Description Language) in detail.
WSDL (Web Services Description Language, Web Services Description Language) is an XML Application that defines Web service descriptions as a set of service access points through which clients can access services that contain document-oriented information or process-oriented calls. access (like a remote procedure call). WSDL first abstracts the access operation and the request/response message used during access, and then binds it to the specific transport protocol and message format to finally define the specific deployed service access point. Related specific deployed service access points become abstract Web services through combination.

one. The basic concept of WSDL
WSDL is a document used to accurately describe Web services, and a 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, the abstract definitions of service access points and messages can be reused because they are separated from the concrete service deployment or data format binding. Message refers to an abstract description of exchanged data; and port type refers to an abstract collection of operations. Concrete protocol and data format specifications for specific port types constitute reusable bindings. A port is defined by associating a web access address with a reusable binding, and a collection of ports is defined as a service.
A WSDL document usually contains 8 important elements, namely definitions, types, import, message, portType, operation, binding, and service elements. These elements are nested within the definitions element, which is the root element of the WSDL document.
WSDL document outer structure diagram:

The basic elements that WSDL services interact with:
Types (message types): containers for data type definitions, using some kind of type system (such as XSD).
Message (message): The abstract typed definition of communication data, which consists of one or more parts.
Part: message parameter
PortType (port type): the specific protocol and data format specification of a specific port type. , which consists of one or more Operations.
Operation: An abstract description of the operations supported by the service. WSDL defines four operations:
1. One-way: the endpoint receives information;
3. Solicit-response: the endpoint sends a message , and then accept relevant messages;
4. Notification (notification[2]): The endpoint sends a message.

Binding: specific protocol and data format specification for a specific port type.
Port: A single endpoint defined as a combination of binding and network address.
Service: A collection of related ports, including their associated interfaces, operations, messages, etc.
There may also be multiple layers within the outer structure.

two. Detailed explanation of the basic structure of WSDL
The following uses a wsdl document to explain the WSDL structure in detail:

<?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=“0”
name=“return” 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>
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
(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 by its name. Apart from providing a namespace (targetNamespace), this element has no other function, so it will not be described in detail.

(2) The types element
WSDL adopts the built-in types of W3C XML Schema as its basic type system. The types element is used as a container for defining various data types that are not described in the built-in types of the XML schema (not quite clear: various data types that are not described in the built-in types of the XML schema). When declaring the availability of message parts, the message definition uses the data types and elements defined in the types element. Type definitions in the WSDL document for 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=“0”
name=“return” nillable=“true” type=“xsd:string” />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
1
2
3
4
5
6
7
8
9
10 11
12 13 14 15 16 17 18 19 20 21 22 The above is the data definition part, which defines Two elements, one is sayHello, the other is sayHelloResponse: sayHello: defines a complex type, only contains a simple string, which will be used to describe the input part of the operation in the future; sayHelloResponse: defines a complex type, only contains a A simple string, used to describe the return value of the operation in the future; here sayHelloResponse is related to sayHello, sayHello is relative to a method, inside: type="xsd:string", name="name", is to determine the incoming name The parameter is of String type, and the name="return" type="xsd:string" in sayHelloResponse is to determine that the type returned by the method sayHello (String name) is of String type.














(3) The import element
The import element makes it possible 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 feature is often useful when users wish to modularize WSDL documents.
The format of import is as follows:

<wsdl:import namespace="http://xxx.xxx.xxx/xxx/xxx" location="http://xxx.xxx.xxx/xxx/xxx.wsdl"/>
1
must have namespace attribute and location attribute :
1.namespace attribute: the value must match the targetNamespace declared in the WSDL document being imported;
2.location attribute: must point to an actual WSDL document, and the document cannot be empty.

(4) message element
The message element describes the payload of the message used by the Web service. The message element can describe the payload of the output or received message; it can also describe the content of the SOAP file header and the error detail element. The way the message element is defined depends on whether RPC-style or document-style messaging is used. In the definition of the message element in this document, this document uses document-style messaging:

<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>
1
2
3
4
5
6
This part is the abstract definition of the message format: two messages sayHelloResponse and sayHelloRequest are defined:

1. sayHelloRequest:
The request message format of the sayHello operation is composed of a message fragment, named parameters, and the elements are the elements in the types we defined earlier;

2. sayHelloResponse:
The response message format of the sayHello operation consists of a message fragment named parameters, and the element is an element in the types we defined earlier;
if RPC-style messaging is used, only the element element in the document needs to be modified to type (??).

(5) portType element
The portType element defines the abstract interface of the Web service. The interface is somewhat similar to the Java interface, which defines an abstract type and method without defining the implementation. In WSDL, the portType element is implemented by the binding and service elements, which are used to describe the Internet protocol, encoding scheme and Internet address used by the Web service implementation.
Multiple operations can be defined in a portType, and an operation can be regarded as a method. The definition of 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>
1
2
3
4
5
6
7
8
portType defines the type of service call mode, which contains an operation sayHello method, and includes input and output to indicate the The operation is a request/response pattern, the request message is sayHelloRequest defined earlier, and the response message is sayHelloResponse defined earlier. The input represents the payload passed to the web service, and the output message represents the payload passed to the client.
This is equivalent to defining an abstract method sayHello in the abstract class, and the definition of method parameters and return value are set in types, and the method name is defined in message.

(6) binding
The binding element maps an abstract portType to a set of concrete protocols (SOAO and HTTP), messaging styles, and encoding styles. Usually the binding element is used together with protocol-specific elements, 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:operation>
</wsdl:binding>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
This part binds the abstract definition of service access point with SOAP and HTTP, and describes how to access the access entry deployed according to the access entry point type described above through SOAP/HTTP.
It stipulates that the soapAction that should be used is "xxx" in the specific SOAP call. This Action is very important in the WebService code call. The specific use needs to refer to the elements defined by the specific protocol.

(7) service element and port element
The service element contains one or more port elements, where each port element represents a different Web service. The port element assigns a URL to a specific binding, and it is even possible for two or more port elements to assign different URLs to the same binding. Example from the docs:

<wsdl:service name="HelloService">
    <wsdl:port name="HelloServiceHttpPort"
        binding="tns:HelloServiceHttpBinding">
        <wsdlsoap:address
            location="http://localhost:8080/xfire/services/HelloService" />
    </wsdl:port>
</wsdl:service>

1
2
3
4
5
6
7
For the study of this WSDL document, the first time I saw it, I felt very strange, and there are many elements in it. To learn, you must first understand the meaning and function of the outer structure, and then understand the elements inside. Meaning and function, some elements have little effect, some elements are very related, and some elements are more important.
WSDL diagram:

—————————————————
Copyright statement: This article is an original article of CSDN blogger "Zheng Rong life", following the CC 4.0 BY-SA copyright agreement, please attach the original source link and this statement.
Original link: https://blog.csdn.net/wenzhi20102321/article/details/68486526

Guess you like

Origin blog.csdn.net/weixin_44659084/article/details/130217332