html5中文学习网

您的位置: 首页 > 网络编程 > ASP.NET » 正文

WSDL文件详解(转贴)下_.NET教程_编程技术

[ ] 已经帮助:人解决问题
详解
在本文作,任何 SOAP 作,能行作名的多作。使用 Java 的客端是很重要的,因使用 Java 的伺服端所使用的介面,利用 Java 的多功能。但使用 COM 的客端倒所,因 COM 不支援多。

<binding> <operation> 元素
Binding 段是,指定通定、序列化、的地方。若 Types、Messages、 PortType 等段抽象的料容,那 Binding 段便理料的具。Binding 段使前三段的抽象具化。

格料息宣告中分出的意是,行相同的服提供者,可一作 (portType) 化。若欲凸自身的差,每提供者可另外提供自。 WSDL 有入 construct 是有好的;因如此一,即可 Bindings Services 段,抽象定置於自身的案中;可其散於服提供者,他把抽象定定成。例如,行可化,一抽象 WSDL 文件明的行作。但每家行是可以自由地,「自」基通定、序列最佳化、。

下列 Binding 段的 WSDL 多例,於此重以方便:

<binding name="fooSampleBinding" type="wsdlns:fooSamplePortType">
<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/foo1"/>
<input name="foo1">
<soap:body use="encoded"
namespace="http://tempuri.org/message/"
encodingStyle=
"http://schemas.xmlsoap.org/soap/encoding/" />
</input>
</operation>
<operation name="foo">
<soap:operation soapAction="http://tempuri.org/action/foo2"/>
<input name="foo2">
<soap:body use="encoded"
namespace="http://tempuri.org/message/"
encodingStyle=
"http://schemas.xmlsoap.org/soap/encoding/" />
</input>
</operation>
</binding>

<binding> 元素有名 (本例中「fooSampleBinding」),以方便 Services 段的 <port> 元素照。它有照 <portType> 的「type」性,在本例中「wsdlns:fooSamplePortType」。第二行是 MSTK2 充元素 <stk:binding>,它可指定 preferredEncoding,或「UTF-8」。

<soap:binding> 元素可指定,使用的式 (rpc) 。性照命名空,以定所使用的 HTTP SOAP 通定。

有 <operation> 元素具有相同的名「foo」。作不同之在於,不同的 <input> 名:「foo1」「foo2」。在 <operation> 元素中,<soap:operation> 元素的「soapAction」性皆相同,都是一 URI。soapAction 性是 SOAP 的 URI,逐字依 SOAP 息使用。以此方式取得的 SOAP 息,有 SOAPAction ;而且以 <soap:operation> 元素中的 URI 其值。然 HTTP 需要 soapAction 性,但非 HTTP 不用。本文刊出,其用途仍然不明。就本例而言,它似乎可用不同的「foo」作。SOAP 1.1 宣,soapAction 可用息的「目的 (intent)」。它更建伺服端,可用此性路由息,而不用剖析整息。上,其用途差很大。<soap:operation> 元素也可以含另一名「style」的性;若特定作需要覆 <soap:binding> 元素中所指定的式,可使用此性。

<operation> 元素所含的 <input>、<output>、 <fault> 元素,可 PortTypes 段的相同元素。在上例中出的只有 <input> 元素。在本例中,三元素都各有一性的「name」性,可用以名相同的作。在例的 <input> 元素中,有 <soap:body> 元素,它可指定入果 SOAP 息之 <body> 的容。此元素有下列性:

Use
它是用以指定料「 (encoded)」或「常值 (literal)」。「常值」的意是,果 SOAP 息所含料的格式,完全依照抽象定 (Types、Messages、 PortTypes 段) 的指定格 。「」的意是,「encodingStyle」性 (考下文) 指定方式。
Namespace
每 SOAP 息的主,都有自己的命名空,以防止名突。此性所指定的 URI,逐字使用於果 SOAP 息之中。
EncodingStyle
以 SOAP 的方式而言,URI 的值是「http://schemas.xmlsoap.org/soap/encoding」。
文件式
在上一段中,<soap:binding> 元素有型性被定成「rpc」。若此性定成「document」,即可改息在上的排序。此些息便成了文件,而不再是函章。在此型中,<message> 元素是定文件格式,而非函章。考下例中的 WSDL 片段:

<definitions
xmlns:stns="(SchemaTNS)"
xmlns:wtns="(WsdlTNS)"
targetNamespace="(WsdlTNS)">

<schema targetNamespace="(SchemaTNS)"
elementFormDefault="qualified">
<element name="SimpleElement" type="xsd:int"/>
<element name="CompositElement" type="stns:CompositeType"/>
<complexType name="CompositeType">
<all>
<element name='a' type="xsd:int"/>
<element name='b' type="xsd:string"/>
</all>
</complexType>
</schema>

<message...>
<part name='p1' type="stns:CompositeType"/>
<part name='p2' type="xsd:int"/>
<part name='p3' element="stns:SimpleElement"/>
<part name='p4' element="stns:CompositeElement"/>
</message>
?</definitions>

此描述有 SimpleElement CompositeElement 元素,以及一宣告型 (CompositeType)。所宣告的唯一 <message> 元素有四部分 (part):p1 是 CompositeType 型;p2 是 int 型;p3 是 SimpleElement;而 p4 是 CompositeElement。下表是四的比,依照「使用/型」分:rpc/literal、document/literal、rpc/encoded、 document/encoded。本表可明,每方式反映在上的情。

rpc / literal
<operation name="method1" style="rpc" ...>
<input>
<soap:body parts="p1 p2 p3 p4"
use="literal"
namespace="(MessageNS)"/>
</input>
</operation>

上情形:
<soapenv:body... xmlns:mns="(MessageNS)"
xmlns:stns="(SchemaTNS)">
<mns:method1>
<mns:p1>
<stns:a>123</stns:a>
<stns:b>hello</stns:b>
</mns:p1>
<mns:p2>123</mns:p2>
<mns:p3>

<stns:SimpleElement>

123

</stns:SimpleElement>
</mns:p3>
<mns:p4>
<stns:CompositeElement>
<stns:a>123</stns:a>
<stns:b>hello</stns:b>
</stns:CompositeElement>
</mns:p4>
</mns:method1>
</soapenv:body>
document / literal / type=
<operation name="method1"
style="document" ...>
<input>
<soap:body parts="p1" use="literal">
</input>
</operation>

上情形:

<soapenv:body... xmlns:stns="(SchemaTNS)">
<stns:a>123</stns:a>
<stns:b>hello</stns:b>
</soapenv:body>

rpc / encoded
<operation name="method1" style="rpc" ...>
<input>
<soap:body parts="p1 p2" use="encoded"
encoding=
"http://schemas.xmlsoap.org/soap/encoding/"
namespace="(MessageNS)"/>
</input>
</operation>

上情形:
<soapenv:body... xmlns:mns="(MessageNS)">
<mns:method1>
<p1 TARGET="_self" HREF="#1"/>
<p2>123</p2>
</mns:method1>
<mns:CompositeType id="#1">
<a>123</a>
<b>hello</b>
</mns:CompositeType>
</soapenv:body>
document / literal / element=
<operation name="method1"
style="document" ...>
<input>
<soap:body parts="p3 p4"

use="literal">
</input>
</operation>

上情形:

<soapenv:body... xmlns:stns="(SchemaTNS)">
<stns:SimpleElement>

123

</stns:SimpleElement>
<stns:CompositeElement>
<stns:a>123</stns:a>
<stns:b>hello</stns:b>
</stns:CompositeElement>
</soapenv:body>

document / encoded
<operation name="method1"
style="document" ...>
<input>
<soap:body parts="p1 p2" use="encoded"
encoding=

"http://schemas.xmlsoap.org/soap/encoding/"
namespace="(MessageNS)"/>
</input>
</operation>

上情形:
<soapenv:body... xmlns:mns="(MessageNS)">
<mns:CompositeType>
<a>123</a>
<b>hello</b>
</mns:CompositeType>
<soapenc:int>123</soapenc:int>
</soapenv:body>


<service> <port> 元素
服即是一 <port> 元素。每 <port> 元素,都以一一的方式,一位置 <binding>。若有一以上的 <port> 元素,相同的 <binding> ,便可以使用其它 URL 作替。

在 WSDL 文件中,可以有一以上的 <service> 元素。多 <service> 元素,可以有多用途。其中之一便是,根 URL 的目的地,埠群化。因此,我只要使用另一 <service>,就可以重新向所有股票要求;而且我的客端程式依然可以正常作,是因在的服群化中,通定完全不更其它的服。多 <service> 服的另一用途是了,根基通定,埠行分。例如,可所有的 HTTP 埠,置於一 <service>;所有的 SMTP 埠置於另一 <service>。客端便可根它能理的通定,搜相的 <service>。

<service name="FOOService">
<port name="fooSamplePort" binding="fooSampleBinding">
<soap:address
location="http://carlos:8080/fooService/foo.asp"/>
</port>
</service>

在一份 WSDL 文件中,<service> 的「name」性,可分出服的不同。因一服可能有埠,所以埠也必有「name」性。


本文已明了 WSDL 文件最著的 SOAP 特色。但明的是,WSDL 不只能在 HTTP 上明 SOAP 而已。在明 SOAP 上,WSDL 的表能力足以使用 HTTP-POST、HTTP-GET、SMTP、其它通定。只要使用 WSDL,不是程式人或一般使用者,都可理 SOAP。人深信,WSDL SOAP 的合,可引全新的用程式,以更底地利用各路服。

在 WSDL 的命名空,有各 XML 元素。下表整理了些元素、性、容,以供考:

元素 性 容 (子)
<definitions> name
targetNamespace
xmlns (其它命名空) <types>
<message>
<portType>
<binding>
<service>
<types> () <xsd:schema>
<message> name <part>
<portType> name <operation>
<binding> name
type <operation>
<service> name <port>
<part> name
type (空值)
<operation> name
parameterOrder <input>
<output>
<fault>
<input> name
message (空值)
<output> name
message (空值)
<fault> name

message (空值)
<port> name
binding <soap:address>

源:
WSDL 1.1
SOAP 1.1
XML 描述入
MS SOAP Toolkit 下站
IDL 至 WSDL 的工具
含 WSDL 至 VB 之 Proxy 生器的免路源
PocketSOAP:SOAP 之相元件、工具、原始程式
3MaHTML5中文学习网 - HTML5先行者学习网
3MaHTML5中文学习网 - HTML5先行者学习网
(责任编辑:)
推荐书籍
推荐资讯
关于HTML5先行者 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助