分类: Java
2008-05-02 17:43:21
<element attribute="attribute-value">contents</element> |
|
WSDL文件示例
让我们来研究一下WSDL文件,看看它的结构,以及如何工作。请注意这是一个非常简单的WSDL文档实例。我们的意图只是说明它最显著的特征。以下的内容中包括更加详细的讨论。
<?xml version="1.0" encoding="UTF-8" ?> <definitions name="FooSample" targetNamespace="" xmlns:wsdlns="" xmlns:typens="" xmlns:xsd="" xmlns:soap="" xmlns:stk="" xmlns=""> <types> <schema targetNamespace="" xmlns="" xmlns:SOAP-ENC="" xmlns: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=""/> <operation name="foo"> <soap:operation soapAction=""/> <input> <soap:body use="encoded" namespace="" encodingStyle="" /> </input> <output> <soap:body use="encoded" namespace="" encodingStyle="" /> </output> </operation> </binding> <service name="FOOSAMPLEService"> <port name="SimplePort" binding="wsdlns:SimpleBinding"> <soap:address location=""/> </port> </service> </definitions> |
int foo(int arg); |
Namespace
<definitions>和子节点<schema>都是namespace属性:
<definitions name="FooSample" targetNamespace="" xmlns:wsdlns="" xmlns:typens="" xmlns:xsd="" xmlns:soap="" xmlns:stk="" xmlns=""> <types> <schema targetNamespace="" xmlns="" xmlns:SOAP-ENC="" xmlns:wsdl="" elementFormDefault="qualified" > </schema> </types> |
xmlns= |
SOAP消息
对于使用WSDL的客户机和服务机来说,研究WSDL文件的一种方法就是决定什么来接受所发送的信息。尽管SOAP使用底层协议,如IP和HTTP等,但应用程序决定了服务器与客户机之间交互的高级协议。也就是说,进行一项操作,比如"echoint"把输入的整数送回,参数的数目、每个参数的类型、以及参数如何传送等因素决定了应用程序特定的协议。有很多方法可以确定此类协议,但我相信最好的方法就是使用WSDL。如果我们用这种视角来看待它,WSDL不只是一种接口协议,而且是一种协议特定的语言。它就是我们超越"固定"协议(IP、HTTP等)所需要的应用程序特定协议。
WSDL可以确定SOAP消息是否遵从RPC或文档风格。RPC风格的消息(就是示例中所用的)看起来像是函数调用。而文档风格的消息则更普通,嵌套层次更小。下面的XML消息就是示例WSDL文件解析后的发送/接受效果,解析使用的是MS SOAP Toolkit 2.0(MSTK2)中的SoapClient对象。
从客户端调用"foo(5131953)"函数:
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="" xmlns:SOAP-ENV=""> <SOAP-ENV:Body> <m:foo xmlns:m=""> <arg>5131953</arg> </m:foo> </SOAP-ENV:Body> </SOAP-ENV:Envelope> 从服务器接受的信息: <?xml version="1.0" encoding="UTF-8" standalone="no"?> <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="" xmlns:SOAP-ENV=""> <SOAP-ENV:Body> <SOAPSDK1:fooResponse xmlns:SOAPSDK1=""> <result>5131953</result> </SOAPSDK1:fooResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope> |
<binding name="SimpleBinding" type="wsdlns:SimplePortType"> <stk:binding preferredEncoding="UTF-8" /> <soap:binding style="rpc" transport=""/> <operation name="foo"> <soap:operation soapAction=""/> <input> <soap:body use="encoded" namespace="" encodingStyle= "" /> </input> <output> <soap:body use="encoded" namespace="" encodingStyle= "" /> </output> </operation> </binding> |
WSDL的Types栏和Messages栏中的XML Schema
WSDL数据类型是基于"XML Schema: Datatypes"(XSD)的,现在已经被W3C推荐。这一文档共有三个版本(1999,2000/10,2001),因此必须在namespace属性的<definitions>元素中指明所使用的是哪一个版本。
xmlns:xsd="" |
前缀 | 代表的Namespace | 描述 |
Soapenc | SOAP 1.1 encoding | |
Wsdl | soap | WSDL 1.1 |
Xsd | XML Schema |
XSD (Soap)类型 | 变量类型 | VB | C++ | IDL | Comments |
anyURI | VT_BSTR | String | BSTR | BSTR | |
base64Binary | VT_ARRAY | VT_UI1 | Byte() | SAFEARRAY | SAFEARRAY(unsigned char) | |
Boolean | VT_BOOL | Boolean | VARIANT_BOOL | VARIANT_BOOL | |
Byte | VT_I2 | Integer | short | short | 转换时验证范围有效性 |
Date | VT_DATE | Date | DATE | DATE | 时间设为 oo:oo:oo |
DateTime | VT_DATE | Date | DATE | DATE | |
Double | VT_R8 | Double | double | double | |
Duration | VT_BSTR | String | BSTR | BSTR | 不转换和生效 |
ENTITIES | VT_BSTR | String | BSTR | BSTR | 不转换和生效 |
ENTITY | VT_BSTR | String | BSTR | BSTR | 不转换和生效 |
Float | VT_R4 | Single | float | float | |
GDay | VT_BSTR | String | BSTR | BSTR | 不转换和生效 |
GMonth | VT_BSTR | String | BSTR | BSTR | 不转换和生效 |
GMonthDay | VT_BSTR | String | BSTR | BSTR | 不转换和生效 |
GYear | VT_BSTR | String | BSTR | BSTR | 不转换和生效 |
GYearMonth | VT_BSTR | String | BSTR | BSTR | 不转换和生效 |
ID | VT_BSTR | String | BSTR | BSTR | 不转换和生效 |
IDREF | VT_BSTR | String | BSTR | BSTR | 不转换和生效 |
IDREFS | VT_BSTR | String | BSTR | BSTR | 不转换和生效 |
Int | VT_I4 | Long | long | long | |
Integer | VT_DECIMAL | Variant | DECIMAL | DECIMAL | 转换时范围生效 |
Language | VT_BSTR | String | BSTR | BSTR | 不转换和生效 |
Long | VT_DECIMAL | Variant | DECIMAL | DECIMAL | 转换时范围生效 |
Name | VT_BSTR | String | BSTR | BSTR | 不转换和生效 |
NCName | VT_BSTR | String | BSTR | BSTR | 不转换和生效 |
negativeInteger | VT_DECIMAL | Variant | DECIMAL | DECIMAL | 转换时范围生效 |
NMTOKEN | VT_BSTR | String | BSTR | BSTR | 不转换和生效 |
NMTOKENS | VT_BSTR | String | BSTR | BSTR | 不转换和生效 |
nonNegativeIntege | VT_DECIMAL | Variant | DECIMAL | DECIMAL | 转换时范围生效 |
nonPositiveInteger | VT_DECIMAL | Variant | DECIMA | DECIMAL | 转换时范围生效 |
normalizedString | VT_BSTR | String | BSTR | BSTR | |
NOTATION | VT_BSTR | String | BSTR | BSTR | 不转换和生效 |
Number | VT_DECIMAL | Variant | DECIMAL | DECIMAL | |
positiveInteger | VT_DECIMAL | Variant | DECIMAL | DECIMAL | 转换时范围生效 |
Qname | VT_BSTR | String | BSTR | BSTR | 不转换和生效 |
Short | VT_I2 | Integer | short | short | |
String | VT_BSTR | String | BSTR | BSTR | |
Time | VT_DATE | Date | DATE | DATE | 日设为1899年12月30日 |
Token | VT_BSTR | String | BSTR | BSTR | 不转换和生效 |
unsignedByte | VT_UI1 | Byte | unsigned char | unsigned char | |
UnsignedInt | VT_DECIMAL | Variant | DECIMAL | DECIMAL | 转换时范围生效 |
unsignedLong | VT_DECIMAL | Variant | DECIMAL | DECIMAL | 转换时范围生效 |
unsignedShort | VT_UI4 | Long | Long | Long | 转换时范围生效 |