Web Service描述语言 WSDL 详解(2)–WSDL文件示例[转]

您所在的位置:网站首页 根据wsdl文件建立服务端 Web Service描述语言 WSDL 详解(2)–WSDL文件示例[转]

Web Service描述语言 WSDL 详解(2)–WSDL文件示例[转]

2022-03-27 04:46| 来源: 网络整理| 查看: 265

  让我们来研究一下wsdl文件,看看它的结构,以及如何工作。请注意这是一个非常简单的wsdl文档实例。我们的意图只是说明它最显著的特征。以下的内容中包括更加详细的讨论。

<?xml version="1.0" encoding="utf-8" ?> <definitions name="foosample"  targetnamespace="http://tempuri.org/wsdl/"  xmlns:wsdlns="http://tempuri.org/wsdl/"  xmlns:typens="http://tempuri.org/xsd"  xmlns:xsd="http://www.w3.org/2001/xmlschema"  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"  xmlns:stk="http://schemas.microsoft.com/soap-toolkit/wsdl-extension"  xmlns="http://schemas.xmlsoap.org/wsdl/">

<types> <schema targetnamespace="http://tempuri.org/xsd"   xmlns="http://www.w3.org/2001/xmlschema"   xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/"   xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"   elementformdefault="qualified" > </schema> </types>

<message name="simple.foo">  <part name="arg" type="xsd:int"/> </message>

<message name="simple.fooresponse">  <part name="result" type="xsd:int"/> </message>

<porttype name="simpleporttype">  <operation name="foo" parameterorder="arg" >   <input message="wsdlns:simple.foo"/>   <output message="wsdlns:simple.fooresponse"/>  </operation> </porttype>

<binding name="simplebinding" type="wsdlns:simpleporttype">  <stk:binding preferredencoding="utf-8" />  <soap:binding style="rpc"   transport="http://schemas.xmlsoap.org/soap/http"/>  <operation name="foo">   <soap:operation soapaction="http://tempuri.org/action/simple.foo"/>   <input>    <soap:body use="encoded" namespace="http://tempuri.org/message/"     encodingstyle="http://schemas.xmlsoap.org/soap/encoding/" />   </input>   <output>    <soap:body use="encoded" namespace="http://tempuri.org/message/"     encodingstyle="http://schemas.xmlsoap.org/soap/encoding/" />   </output>  </operation> </binding>

<service name="foosampleservice">  <port name="simpleport" binding="wsdlns:simplebinding">   <soap:address location="http://carlos:8080/foosample/foosample.asp"/>  </port> </service> </definitions>

  以下是该实例文档的总述:稍后我将详细讨论每一部分的细节。

  第一行申明该文档是xml。尽管这并不是必需的,但它有助于xml解析器决定是否解析wsdl文件或只是报错。第二行是wsdl文档的根元素:<definitions>。一些属性附属于根元素,就像<schema>子元素对于<types>元素。

  <types>元素包含了types栏。如果没有需要声明的数据类型,这栏可以缺省。在wsdl范例中,没有应用程序特定的types声明,但我仍然使用了types栏,只是为了声明schema namespaces。

  <message>元素包含了messages栏。如果我们把操作看作函数,<message>元素定义了那个函数的参数。<message>元素中的每个<part>子元素都和某个参数相符。输入参数在<message>元素中定义,与输出参数相隔离–输出参数有自己的<message>元素。兼作输入、输出的参数在输入输出的<message>元素中有它们相应的<part>元素。输出<message>元素以"response"结尾,就像以前所用的"fooresponse"。每个<part>元素都有名字和类型属性,就像函数的参数有参数名和参数类型。

  用于交换文档时,wsdl允许使用<message>元素来描述交换的文档。

  <part>元素的类型可以是xsd基类型,也可以是soap定义类型(soapenc)、wsdl定义类型(wsdl)或是types栏定义的类型。

  一个porttypes栏中,可以有零个、单个或多个<porttype>元素。由于抽象porttype定义可以放置在分开的文件中,在某个wsdl文件中没有<porttype>元素是可能的。上面的例子里只是用了一个<porttype>元素。而一个<porttype>元素可在<operation>元素中定义一个或是多个操作。示例仅使用了一个名为"foo"的<operation>元素。这和某个函数名相同。<operation>元素可以有一个、两个、三个子元素:<input>, <output> 和<fault>元素。每个<input>和<output>元素中的消息都引用message栏中的相关的<message>元素。这样,示例中的整个<porttype>元素就和以下的c函数等效:

 

 int foo(int arg);

  这个例子足见xml和c相比要冗长的多。(包括<message>元素,xml在示例中共使用了12行代码来表达相同的单行函数声明。)

  bindings栏可以有零个、一个或者多个<binding>元素。它的意图是制定每个<operation>通过网络调用和回应。services栏同样可以有零个、一个、多个<service>元素。它还包含了<port>元素,每个<port>元素引用一个bindings栏里的<binding>元素。bindings和services栏都包含wsdl文档。

原文地址:http://www.yesky.com/20011013/200759_1.shtml



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3