【转】wsdl完全解析

WSDL(Web Services Description Language)是一种基于XML的语言,用于描述Web服务的功能、消息格式及访问方式。本文详细介绍了WSDL的基本概念、文档结构及其核心元素,如portType、message、types和binding等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

WSDL is an XML-based language for describing Web services and how to access them.
WSDL
是一种基于XML的语言。它的作用是描述和访问网页服务。

What You Should Already Know
你应该已经知道的

Before you continue you should have a basic understanding of the following:
在你继续下面的学习之前你应该对以下内容有个基本认识:

  • XML
  • XML Namespaces 
    XML
    命名空间
  • XML Schema 
    格式

If you want to study these subjects first, find the tutorials on our Home page.
如果你想先学习这些内容,请看我们主页上的教程。

What is WSDL?
什么是WSDL

  • WSDL stands for Web Services Description Language 
    &S226; WSDL
    是网页服务描述语言 (Web Services Description Language)的缩写
  • WSDL is written in XML 
    &S226; WSDL
    是以XML形式写成的。
  • WSDL is an XML document 
    &S226; WSDL
    是一份XML文档
  • WSDL is used to describe Web services 
    &S226; WSDL
    用于描述网页服务
  • WSDL is also used to locate Web services 
    &S226; WSDL
    也用于给网页服务定位
  • WSDL is not yet a W3C standard 
    &S226; WSDL
    目前还不是W3C标准

WSDL Describes Web Services 
WSDL
描述了网页服务

WSDL stands for Web Services Description Language.
&S226; WSDL
是网页服务描述语言 (Web Services Description Language)的缩写

WSDL is a document written in XML. The document describes a Web service. It specifies the location of the service and the operations (or methods) the service exposes.
WSDL
是以XML语言写成的文档。文档描述了网页服务。它指定了服务的位置并揭示了服务的具体操作。

WSDL Development History at W3C
WSDL
W3C的发展史

WSDL 1.1 was submitted as a W3C Note by Ariba, IBM and Microsoft for describing services for the W3C XML Activity on XML Protocols in March 2001.
2001
3月,Ariba, IBM  Microsoft提交WSDL 1.1作为一个W3C Note(注释),用于为XML协议上的W3C XML Activity描述服务。

(a W3C Note is made available by the W3C for discussion only. Publication of a Note by W3C indicates no endorsement by W3C or the W3C Team, or any W3C Members)
(一份W3C注释是W3C提供的仅供讨论的内容。W3C发行的注释并不代表注释经过W3CW3C工作组,或任何W3C成员的认可和肯定)。

The first Working Draft of WSDL 1.2 was released by W3C in July 2002.
WSDL 1.2
的首篇工作草案于20027月由W3C发行。

WSDL 文档
w3pop.com / 2006-09-21

WSDL 介绍 WSDL 端口

A WSDL document is just a simple XML document.
一份WSDL文档是一份简单的XML文档。

It contains set of definitions to describe a web service.
它包含了几组用于描述网页服务的定义。


The WSDL Document Structure
WSDL
文档结构

A WSDL document describes a web service using these major elements:
一份WSDL文档用到这些重要元素来描述网页服务:

Element
元素

Defines
定义

<portType>

The operations performed by the web service
由网页服务进行的操作

<message>

The messages used by the web service
网页服务使用的信息

<types>

The data types used by the web service
网页服务使用的数据类型

<binding>

The communication protocols used by the web service
网页服务使用的交流协议

The main structure of a WSDL document looks like this:
一份WSDL文档的主要结构会像这样:

<definitions>
<types>
   definition of types........

</types>

<message>
   definition of a message....

</message>

<portType>
   definition of a port.......

</portType>

<binding>
   definition of a binding....


</binding>

</definitions>

A WSDL document can also contain other elements, like extension elements and a service element that makes it possible to group together the definitions of several web services in one single WSDL document.
一份WSDL文档可能也会包含其他元素,像extension(扩展)元素和service(服务)元素,service元素可以把若干个网页服务的定义合在一起放在一份单独的WSDL文档里。

For a complete syntax overview go to the chapter WSDL Syntax.
想了解关于全部语法,请阅读WSDL Syntax.这章。


WSDL Ports
WSDL
端口

The <portType> element is the most important WSDL element. 
<portType>
元素是最重要的WSDL元素

It describes a web service, the operations that can be performed, and the messages that are involved.
它描述了网页服务,可进行的操作,以及涉及到的信息。

The <portType> element can be compared to a function library (or a module, or a class) in a traditional programming language.
<portType>
元素可以比喻为传统设计语言里的函数库(或一个模块,一个类)


WSDL Messages
WSDL
信息

The <message> element defines the data elements of an operation.
<message>
元素定义了一项操作的数据元素。

Each message can consist of one or more parts. The parts can be compared to the parameters of a function call in a traditional programming language. 
每条信息都由一部分或几部分组成。这些部分可比作是在传统设计语言里被调用的函数的参数。


WSDL Types
WSDL
类型

The <types> element defines the data type that are used by the web service.
<types>
元素定义了被网页服务所用的数据类型。

For maximum platform neutrality, WSDL uses XML Schema syntax to define data types.
为了最大限度的平台中立,WSDLXML格式语法来定义数据类型。


WSDL Bindings
WSDL 
捆绑

The <binding> element defines the message format and protocol details for each port.
<binding>
元素为每个端口定义了信息格式化和协议细节。


WSDL Example
WSDL
举例

This is a simplified fraction of a WSDL document:
下面是一份WSDL文档的简化了的片段:

<message name="getTermRequest">

   <part name="term" type="xs:string"/>
</message>

<message name="getTermResponse">
   <part name="value" type="xs:string"/>

</message>
<portType name="glossaryTerms">
  <operation name="getTerm">
      <input message="getTermRequest"/>
      <output message="getTermResponse"/>
  </operation>
</portType>

In this example the <portType> element defines "glossaryTerms" as the name of a port, and "getTerm" as the name of an operation.
在这个例子里<portType>元素把"glossaryTerms"定义为一个端口的名称,"getTerm"定义为一项操作的名称。

The "getTerm" operation has an input message called "getTermRequest" and an output message called "getTermResponse".
"getTerm"
操作有一条"getTermRequest"的输入信息和一条"getTermResponse".的输出信息

The <message> elements define the parts of each message and the associated data types.
<message>
元素定义了每条元素的部分(part)和相联系的数据类型。

Compared to traditional programming, glossaryTerms is a function library, "getTerm" is a function with "getTermRequest" as the input parameter and getTermResponse as the return parameter.
与传统程序设计相比,glossaryTerms是个函数库,"getTerm"是个以"getTermRequest"作为输入参数,getTermResponse作为输出参数的函数

WSDL 端口
w3pop.com / 2006-09-21

WSDL 文档 WSDL 绑定

A WSDL port describes the interfaces (legal operations) exposed by a web service.
WSDL
端口描述了由网页服务所揭示的界面(interface)(合法操作)


WSDL Ports
WSDL
端口

The <portType> element is the most important WSDL element. 
<portType>
元素是最重要的WSDL元素。

It defines a web service, the operations that can be performed, and the messagesthat are involved.
它定义了网页服务,可进行的操作,以及涉及到的信息。

The port defines the connection point to a web service. It can be compared to a function library (or a module, or a class) in a traditional programming language. Each operation can be compared to a function in a traditional programming language.
端口定义了与网页服务的连接点。它可以比作是传统设计语言里的函数库(或一块模板,或一个类)。每项操作可比成是传统设计语言里的一个函数。


Operation Types
操作类型

The request-response type is the most common operation type, but WSDL defines four types:
请求回操作类型是最常见的操作类型,但WSDL定义的有四种:

Type
类型

Definition
定义

One-way

The operation can receive a message but will not return a response
可接受信息但不回复的操作

Request-response

The operation can receive a request and will return a response
接受并回复信息的操作

Solicit-response

The operation can send a request and will wait for a response
可发出请求并会等待回复的操作

Notification

The operation can send a message but will not wait for a response
可发出信息但不会等待回复的操作

 


One-Way Operation
单向操作

A one-way operation example:
单向操作的例子:

<message name="newTermValues">
   <part name="term" type="xs:string"/>
   <part name="value" type="xs:string"/>

</message>
<portType name="glossaryTerms">
   <operation name="setTerm">
      <input name="newTerm" message="newTermValues"/>

   </operation>
</portType >

In this example the port "glossaryTerms" defines a one-way operation called "setTerm". 
在这个例子里"glossaryTerms端口定义了称作"setTerm".的单向操作

The "setTerm" operation allows input of new glossary terms messages using a "newTermValues" message with the input parameters "term" and "value". However, no output is defined for the operation. 
"setTerm"
操作允许利用输入参数为“term""value"的名为"newTermValues"的信息进行大量全新条款信息的输入。但是,这项操作没有定义有关输出的内容。


Request-Response Operation
请求回复 操作

A request-response operation example:
一个请求回复操作的例子:

<message name="getTermRequest">
   <part name="term" type="xs:string"/>

</message>

<message name="getTermResponse">
   <part name="value" type="xs:string"/>
</message>
<portType name="glossaryTerms">
  <operation name="getTerm">
      <input message="getTermRequest"/>
      <output message="getTermResponse"/>
  </operation>
</portType>

In this example the port "glossaryTerms" defines a request-response operation called "getTerm".
这个例子里端口"glossaryTerms"定义了一个名为"getTerm"请求回复操作

The "getTerm" operation requires an input message called "getTermRequest" with a parameter called "term", and will return an output message called "getTermResponse" with a parameter called "value".
"getTerm"
操作需要一个参数为"term"的名为"getTermRequest"的输入信息,并且会返回一条参数为"value".的名为“getTermResponse"的输出信息

WSDL 绑定
w3pop.com / 2006-09-21

WSDL 端口 WSDL  UDDI

WSDL bindings defines the message format and protocol details for a web service.
WSDL 
绑定(bindings)定义了网页服务的信息格式和协议细节


Binding to SOAP
绑定到SOAP

A request-response operation example:
一个要求响应操作例子

<message name="getTermRequest">
   <part name="term" type="xs:string"/>
</message>

<message name="getTermResponse">
   <part name="value" type="xs:string"/>
</message>
<portType name="glossaryTerms">
  <operation name="getTerm">
      <input message="getTermRequest"/>
      <output message="getTermResponse"/>
  </operation>
</portType>
<binding type="glossaryTerms" name="b1">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" />
  <operation>

    <soap:operation
     soapAction="http://example.com/getTerm"/>
    <input>
      <soap:body use="literal"/>
    </input>
    <output>

      <soap:body use="literal"/>
    </output>
  </operation>
</binding>

The binding element has two attributes - the name attribute and the type attribute.
Binding
元素有两个属性—name(名称)属性和type(类型)属性

The name attribute (you can use any name you want) defines the name of the binding, and the type attribute points to the port for the binding, in this case the "glossaryTerms" port.
Name
属性(你可以任意起名称)定义了绑定的名称,type属性指向了用于绑定的端口,在这个例子里端口是"glossaryTerms"

The soap:binding element has two attributes - the style attribute and the transport attribute.
soap:binding
元素有两个属性—style(种类)属性和transport(运送)属性

The style attribute can be "rpc" or "document". In this case we use document. The transport attribute defines the SOAP protocol to use. In this case we use HTTP.
Style
属性可以是"rpc" "document".在这个例子里我们用"document"属性。Transport属性定义了使用的SOAP协议。这个例子里我们用HTTP

The operation element defines each operation that the port exposes.
Operation
元素定义了每项揭示端口操作。

For each operation the corresponding SOAP action has to be defined. You must also specify how the input and output are encoded. In this case we use "literal".
对每项操作而言,相应的SOAP行为都必须被定义。你也必须指定输入和输出是怎样被编码的。在这个例子里我们用"literal"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值