asp学习网: 首页 >> asp.net >> SOAP:简单对象访问协议

SOAP:简单对象访问协议

 
7.1 RPC和SOAP体
RPC方法调用和应答都包含在SOAP Body元素中(见4.3节),它们使用如下的表示形式:

一个方法调用用一个结构表示
一个方法调用被看作一个单个的结构,每个[in]和[in/out]参数有一个accessor。结构
的名和类型与方法相同。
每个[in]和[in/out]参数都被看作一个accessor,这个accessor的名和类型与参数的名
和类型相对应。它们的出现顺序和方法中定义的参数顺序相同。
一个方法应答用一个结构表示。
一个方法应答被看作一个单个的结构,返回值和每个[in]和[in/out]参数有一个access
or。第一个accessor是返回值,之后是参数accessor,参数accessor的出现顺序和方法
中定义的参数顺序相同。
每个参数accessor的名称和类型与参数的名称和类型相对应。返回值accessor的名称并
不重要。同样,结构的名称也不重要,不过,通常在方法名称的后面加上字符串"Respo
nse"作为结构的名称。
方法错误使用SOAP Fault元素(见4.4节)表示。如果绑定的协议有额外的规则表示错误
,则这些规则也必须要遵从。
正如上面所述,方法调用和应答结构可以按照第5节中规则编码,或者用encodingStyle
属性(见4.1.1节)指定编码方式。
应用程序可以处理缺少参数的请求,但是可能返回一个错误。
因为返回结果表示调用成功,错误表示调用失败,所以,在方法应答中同时包含返回结
果和错误是错误的。
7.2 RPC和SOAP头
在RPC编码中,可能会有与方法请求有关但不是正规的方法signature的附加信息。如果
这样,它必须作为SOAP头元素的子元素。
使用这种头元素的一个例子是在消息中传递事务ID。由于事务ID不是方法signature的一
部分,通常由底层的组件而不是应用程序代码控制,所以没有一种直接的方法在调用中
传递这个必要的信息。通过在头中添加一个给定名字的条目,接收方的事务管理器就可
以析取这个事务ID,而且不影响远程过程调用的代码。
8. 安全性考虑
这篇文档中没有涉及完整性和保密性,这些问题将在以后的版本中描述。
9. 参考文献
[1] S. Bradner, "The Internet Standards Process -- Revision 3", RFC2026, Har
vard University, October 1996
[2] S. Bradner, "Key words for use in RFCs to Indicate Requirement Levels",
RFC 2119, Harvard University, March 1997
[3] E. Whitehead, M. Murata, "XML Media Types", RFC2376, UC Irvine, Fuji Xer
ox Info. Systems, July 1998
[4] T. Berners-Lee, R. Fielding, L. Masinter, "Uniform Resource Identifiers
(URI): Generic Syntax", RFC 2396, MIT/LCS, U.C. Irvine, Xerox Corporation, A
ugust 1998.
[5] R. Fielding, J. Gettys, J. C. Mogul, H. Frystyk, T. Berners-Lee, "Hypert
ext Transfer Protocol -- HTTP/1.1", RFC 2616, U.C. Irvine, DEC W3C/MIT, DEC,
W3C/MIT, W3C/MIT, January 1997
[6] H. Nielsen, P. Leach, S. Lawrence, "An HTTP Extension Framework", RFC 27
74, Microsoft, Microsoft, Agranat Systems
[7] W3C Recommendation "The XML Specification"
[8] W3C Recommendation "Namespaces in XML"
[9] W3C Working Draft "XML Linking Language". This is work in progress.
[10] W3C Working Draft "XML Schema Part 1: Structures". This is work in prog
ress.
[11] W3C Working Draft "XML Schema Part 2: Datatypes". This is work in progr
ess.
[12] Transfer Syntax NDR, in "DCE 1.1: Remote Procedure Call"
[13] N. Freed, N. Borenstein, "Multipurpose Internet Mail Extensions (MIME)
Part One: Format of Internet Message Bodies", RFC2045, Innosoft, First Virtu
al, November 1996
A. SOAP封装举例
A.1 请求编码举例
例5 类似于例1,但有一个必要的头
POST /StockQuote HTTP/1.1
Host: www.stockquoteserver.com
Content-Type: text/xml; charset="utf-8"
Content-Length: nnnn
SOAPAction: "Some-URI"
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding//>
<SOAP-ENV:Header>
<t:Transaction
xmlns:t="some-URI"
SOAP-ENV:mustUnderstand="1">
5
</t:Transaction>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<m:GetLastTradePrice xmlns:m="Some-URI">
<symbol>DEF</symbol>
</m:GetLastTradePrice>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
例6 类似于例1,但有多个请求参数
POST /StockQuote HTTP/1.1
Host: www.stockquoteserver.com
Content-Type: text/xml; charset="utf-8"
Content-Length: nnnn
SOAPAction: "Some-URI"
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding//>
<SOAP-ENV:Body>
<m:GetLastTradePriceDetailed
xmlns:m="Some-URI">
<Symbol>DEF</Symbol>
<Company>DEF Corp</Company>
<Price>34.1</Price>
</m:GetLastTradePriceDetailed>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
A.2 应答编码举例
例7 与例2类似,但有必要的头部
HTTP/1.1 200 OK
Content-Type: text/xml; charset="utf-8"
Content-Length: nnnn
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding//>
<SOAP-ENV:Header>
<t:Transaction
xmlns:t="some-URI"
xsi:type="xsd:int" mustUnderstand="1">
5
</t:Transaction>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<m:GetLastTradePriceResponse
xmlns:m="Some-URI">
<Price>34.5</Price>
</m:GetLastTradePriceResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
例8 与例2类似,但有一个结构
HTTP/1.1 200 OK
Content-Type: text/xml; charset="utf-8"
Content-Length: nnnn
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding//>
<SOAP-ENV:Body>
<m:GetLastTradePriceResponse
xmlns:m="Some-URI">
<PriceAndVolume>
<LastTradePrice>
34.5
</LastTradePrice>
<DayVolume>
10000
</DayVolume>
</PriceAndVolume>
</m:GetLastTradePriceResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
例9 与例2类似,但处理必要的头出错
HTTP/1.1 500 Internal Server Error
Content-Type: text/xml; charset="utf-8"
Content-Length: nnnn
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/>
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:MustUnderstand</faultcode>
<faultstring>SOAP Must Understand Error</faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
例10 与例2类似,但处理Body出错
HTTP/1.1 500 Internal Server Error
Content-Type: text/xml; charset="utf-8"
Content-Length: nnnn
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/>
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Server</faultcode>
<faultstring>Server Error</faultstring>
<detail>
<e:myfaultdetails xmlns:e="Some-URI">
<message>
My application didn't work
</message>
<errorcode>
1001
</errorcode>
</e:myfaultdetails>
</detail>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

from:asp学习网/title:SOAP:简单对象访问协议/ time:2007-6-18 10:41:59

本文主题SOAP

asp教程 ©2006-2007 aspxuexi.com | 关于站点 | 版权隐私 | 站内搜索
复制或者翻版 请于夜间进行