JIYIK CN >

Current Location:Home > Learning > NETWORK >

WSDL looks like this

Author:JIYIK Last Updated:2025/03/18 Views:

When I first started learning Webservice, I found that there were quite a lot of knowledge points involved, and each point could be a school of its own. Especially when I saw WSDL, I looked up information for a long time, but I was still a little confused and didn't have a clear understanding of it. As I wrote some WSDL cases in my later work, I gradually understood its internal principles.

First, let's take a look at the role of WSDL: WSDL (Web Service Description Language) uses XML format files to describe available Web services. In fact, to put it simply, it is a standard. Terminals create Web services on the network according to this standard, and clients also connect to this service according to this standard and obtain the operations they need based on the WSDL file.

Next, I would like to talk about the development process of WSDL. Understanding the history of WSDL will avoid confusion in future learning.

The first version of WSDL was WSDL1.0, which was developed by IBM, Microsoft and Ariba in September 2000. Its purpose was to describe the SOAP toolkit for Web Services. Then in March 2001, WSDL 1.1 was released, which marked that WSDL was on the right track. However, there were not many changes between 1.0 and 1.1. Two years later, WSDL1.2 was released as a W3C working draft in June 2003. According to W3C, WSDL1.2 is simpler and more flexible for developers to use than 1.1. However, WSDL1.2 does not support most SOAP services.

In June 2007, WSDL 1.2 was officially renamed WSDL 2.0, and WSDL 2.0 became the recommended version of W3C. The reason for this change is that version 2.0 has substantial changes compared to version 1.1, so it has been upgraded to a higher level.

So the two popular versions of WSDL are WSDL2.0 and WSDL1.1. Although WSDL2.0 is the version recommended by W3C, most manufacturers still support WSDL1.1. For example, we all know that ZendStudio, an official IDE for PHP, and Eclipse, a Java IDE, when we use them to create a new WSDl file, the format followed by this WSDl file is still the WSDL1.1 version format. In my daily work, the WSDL used also follows the 1.1 version format.

So what are the formats of WSDL1.1 and WSDL2.0? Let me introduce them to you.

First, let's look at WSDL1.1. According to this standard, the WSDL file contains the following seven items:

1. Types

It can be considered as a container. The content in the container is the description of the data type. Of course, XML Schema is needed to achieve this goal. Then the format of this container is as follows

<wsdl:types>
    <xsd:schema targetNamespace="http://www.test.com/WSDLFile/">
      <xsd:element name="Operation">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element name="in" type="xsd:string"/>
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
      <xsd:element name="OperationResponse">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element name="out" type="xsd:string"/>
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
    </xsd:schema>
  </wsdl:types>

2. Message

Make an abstract definition of the operation interface. The format is as follows:

<wsdl:message name="OperationRequest">
    <wsdl:part element="tns:Operation" name="parameters"/>
  </wsdl:message>
<wsdl:message name="OperationResponse">
    <wsdl:part element="tns:OperationResponse" name="parameters"/>
  </wsdl:message>

Messages包含了一个或者多个part 元素,对于Message的属性name的值是唯一的,和当前整个WSDL文件中的人和一个Message的name值都不能相同。Part的属性name的值也是唯一的,和当前Message中的其它的任何一个part的name的值都不能相同,当然处于不同的Message中的part的name的值可以相同。

每一个part元素都关联message-type属性,这个message-type属性一般包含两部分:element和type。Message中的每一个part对应Types中的一个element元素,并且part的element属性的值为 Types中的element的name的值,前面再加上tns: ,举例如下(下面的代码是摘自 http://www.w3.org/TR/wsdl#_introduction):

<types>
        <schema .... >
           <element name="PO" type="tns:POType"/>
           <complexType name="POType">
               <all>
                   <element name="id" type="string/>
                   <element name="name" type="string"/>
                   <element name="items">
                       <complexType>
                           <all>
                               <element name="item" type="tns:Item" minOccurs="0" maxOccurs="unbounded"/>
                           </all>
                       </complexType>
                   </element>
              </all>
           </complexType>
 
           <complexType name="Item">
               <all>
                   <element name="quantity" type="int"/>
                   <element name="product" type="string"/>
               </all>
           </complexType>
           <element name="Invoice" type="tns:InvoiceType"/>
           <complexType name="InvoiceType">
               <all>
                   <element name="id" type="string"/>
               </all>
           </complexType>
        </schema>
    </types>
<message name="PO">
        <part name="po" element="tns:PO"/>
        <part name="invoice" element="tns:Invoice"/>
    </message>

对于Message这一项在WSDL2.0中已经去掉了。

3. Port Type

由终端定义的一系列的抽象方法,其格式如下  

<wsdl:portType name="WSDLFile">
    <wsdl:operation name="Operation">
      <wsdl:input message="tns:OperationRequest"/>
      <wsdl:output message="tns:OperationResponse"/>
    </wsdl:operation>
</wsdl:portType>

同样的,port type 的属性name的值不同于整个WSDL文档中其他的prottype的name的值。

WSDL有四种传递方式:

One-way: 终端服务接受消息

<wsdl:operation name="Operation">
      <wsdl:input message="tns:OperationRequest"/>
 </wsdl:operation>

Request-response:终端服务接受消息,并且发送相关的消息给客户端

<wsdl:operation name="Operation">
      <wsdl:input message="tns: OperationRequest"/>
      <wsdl:output message="tns:OperationResponse"/>
</wsdl:operation>

Solicit-response:终端发送一个消息,并且接受一个相关消息

<wsdl:operation name="Operation">
<wsdl:output message="tns:OperationResponse"/>
      <wsdl:input message="tns: OperationRequest"/>
</wsdl:operation>

Notification:终端服务发送一个消息

<wsdl:operation name="Operation">
<wsdl:output message="tns:OperationResponse"/>
</wsdl:operation>

对于input和output的name的值来说,每一个input或者output的name的值在所有的input和output中是唯一的。当然WSDL也提供了默认的命名规则。此外对于input或者output的属性message的值为Message元素中的属性name的值,前面加上tns:

4. Binding

为porttype中的operation和message指定一个具体的传输协议(SOAP协议)和数据格式

<wsdl:binding name="WSDLFileSOAP" type="tns:WSDLFile">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="Operation">
      <soap:operation soapAction="http://www.test.com/WSDLFile/Operation"/>
      <wsdl:input>
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>

同样的binding的属性name的值在所有的binding的name中是唯一的。此时binding是通过type和porttype进行绑定的,type的值为porttype的name的值在前面加上tns:。然后binding中的子元素wsdl:operation 参照 上面的operation,只是对每一个元素进行了SOAP绑定。

除了这些,在上面的示例中我们还看到有 soap:binding,soap:operation,soap:body等,这些的作用就是将soap协议绑定到接口上,因为在传输的过程中是按照soap协议传输的。

首先看soap:binding,其style的值就是operation的type属性的默认值,所以在wsdl:operation中我们可以不指定type属性。接下来是soap:operation,soapAction指定了消息请求的地址,也就是消息发送到哪个接口或者操作方法。还有就是soap:body指定了消息部分在SOAP协议中是以什么方式传输的。其中use属性是必须的,除此之外还有parts,encodingstyle和namespace属性,但是这几个不是必须的。use属性的值有两个literal和encoded,以此判断消息部分是否使用某种编码规则进行编码,或者定义一种具体的模式。

在实际应用中SOAP协议对于开发者来说是透明的,编程语言中都将SOAP协议封装成了具体的函数来供我们开发调用。如果想要详细了解SOAP协议的机制,可以参考http://www.w3.org/TR/soap12-part1/#soapbody

5. Port

定义了链接web service的地址,这个地址就是一个HTTP URL

<wsdl:service name="WSDLFile">
    <wsdl:port binding="tns: WSDLFileSOAP" name="WSDLFileSOAP">
      <soap:address location="http://www.test.com/"/>
    </wsdl:port>
</wsdl:service>

The value of the port name is unique among all port names. The value of the attribute binding is the value of the name in the binding element above plus tns:

It should be noted that a port can only specify one address, and the port cannot contain other elements except the address.

6. Service

Can be understood as a group of related ports

<wsdl:service name="WSDLFile">
    <wsdl:port binding="tns: WSDLFileSOAP" name="WSDLFileSOAP">
      <soap:address location="http://www.test.com/"/>
    </wsdl:port>
</wsdl:service>

Similarly, its name value is unique among all service names. A group of ports under a service are related. 1. Each port cannot communicate with each other; 2. If multiple ports in a service share a porttype, but each port has a different address and binding, then these ports need to provide equivalent behaviors so that the WSDL document can select the corresponding port for communication according to a certain standard. 3. Because the information provided by these ports has a certain correlation, the porttype of a service can be understood based on these ports.

The above is the format of WSDL1.1. In WSDL2.0, in addition to removing the Message item, the port type is also replaced by Interface. Since I usually use WSDL1.1 and have never used 2.0, I don't know much about it. I will study 2.0 carefully and then present the WSDL2.0 version to you. Of course, if you have any good suggestions, you are also welcome to leave a message below so that we can discuss and make progress together.

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

What multipart/form-data does in post Upload upload files

Publish Date:2025/03/18 Views:63 Category:NETWORK

Everyone has used the attribute enctype="multipart/form-data" when uploading files using a form. What is the role of multipart/form-data? Let's talk about this topic. First, let's look at a case Look at the first code   form action= "handl

About application/x-www-form-urlencoded

Publish Date:2025/03/18 Views:147 Category:NETWORK

As a data format of form, application/x-www-form-urlencoded has its own characteristics   form action= "handle.php" method= "post"    input type= "text" name= " uname"   class= " uname" /br /    input type= "text" name= "email" class=

My understanding of webservice is this

Publish Date:2025/03/18 Views:147 Category:NETWORK

Recently, I encountered such a project at work (temporarily named Project A). Project A itself was developed in PHP, but its data came from another project developed in Java (temporarily named Project B). Project A could not operate the dat

Which technology do you choose to implement the web chat room?

Publish Date:2025/03/18 Views:61 Category:NETWORK

With the rise of HTML5 Websockets, web chat applications are becoming more and more popular. Recently, I am working on a mobile web application, the core function of which is to implement web chat on the mobile phone. Of course, the functio

Implementing a group chat room using socket.io

Publish Date:2025/03/18 Views:65 Category:NETWORK

This article will share with you an example of using socket.io to realize the function of group chat. If you want to use socket.io, you must use nodejs to implement the server, so we need to install socket.io in nodejs Install socket.io How

Getting started with FastCGI

Publish Date:2025/03/18 Views:164 Category:NETWORK

In "First Contact with CGI", we mentioned the operating mechanisms of CGI and Server APIs, as well as their respective advantages and disadvantages. In this chapter, we will learn about FastCGI, which combines the advantages of CGI and Serv

9 Ways to Fix NET::ERR_CERT_AUTHORITY_INVALID Error

Publish Date:2025/03/17 Views:176 Category:NETWORK

Sometimes even after you have an SSL certificate installed on your website, your website’s users may encounter NET::ERR_CERT_AUTHORITY_INVALID an invalid certificate authority error. Despite the intimidating name, the invalid certificate

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial