读书人

深入显出WS-Addressing(转)

发布时间: 2012-12-20 09:53:21 作者: rapoo

深入浅出WS-Addressing(转)
1.为什么需要WS-Addressing

---[HTTP request - http://localhost:80/jaxws-wsaddressing_replyto/addnumbers]---Content-length: 627Content-type: text/xml;charset=utf-8Accept: text/xml, multipart/relatedSoapaction: "http://server.wsaddressing_replyto/AddNumbersImpl/addNumbersRequest"<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S=http://schemas.xmlsoap.org/soap/envelope /xmlns:wsa="http://www.w3.org/2005/08/addressing"><S:Header><To xmlns="http://www.w3.org/2005/08/addressing">http://localhost:80/jaxws-wsaddressing_replyto/addnumbers </To><Action xmlns="http://www.w3.org/2005/08/addressing">http://server.wsaddressing_replyto/AddNumbersImpl/addNumbersRequest</Action></S:Header><S:Body><ns2:addNumbers xmlns:ns2="http://server.wsaddressing_replyto/"><arg0>10</arg0><arg1>20</arg1></ns2:addNumbers></S:Body></S:Envelope>--------------------

但是,这种处理方法,对应简单的点到点数据传输是可以的,但是一旦遇到了异步的,分布式的系统的话,这样的解决方法就不行了,具体问题如下:

1)如果在异步传输下,服务A发送数据给服务B,但是服务B的正常响应,非正常响应,错误响应都是不同的,那么怎么在http数据包来定义呢?

2) 如果服务A发送数据给服务B,但是调用的是服务B的不同版本。比如服务B有三个不同的版本,需要通过调用时候传递的参数来决定调用的版本。那么简单的http数据包定义能应付吗?

为了解决这些技术问题,IBM,MS,BEA等公司联合推出了WS- Addressing协议。

WS- Addressing协议的最新官方文档如下:

http://www.w3.org/Submission/ws-addressing/


WS- Addressing协议最简单的定义就是,在SOAP消息的Header中,用一系列XML标签定义了服务传递中间的目的地,Action,ReplyTo,Fault处理等等传输层细节。

---[HTTP request -http://localhost:80/jaxws-wsaddressing_replyto/addnumbers]---Content-length: 627Content-type: text/xml;charset=utf-8Accept: text/xml,multipart/relatedSoapaction:"http://server.wsaddressing_replyto/AddNumbersImpl/addNumbersRequest"<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S=http://schemas.xmlsoap.org/soap/envelope /xmlns:wsa="http://www.w3.org/2005/08/addressing"><S:Header><wsa:To>http://localhost:80/jaxws-wsaddressing_replyto/addnumbers</wsa:To><wsa:ReplyTo><Address>http://www.w3.org/2005/08/addressing/anonymous</Address></wsa:ReplyTo><wsa:FaultTo><Address>http://www.w3.org/2005/08/addressing/anonymous</Address></wsa:FaultTo><wsa:MessageID>uuid:71dc765e-1c1f-4fff-ac77-1681eb416005</wsa:MessageID><To xmlns="http://www.w3.org/2005/08/addressing">http://localhost:80/jaxws-wsaddressing_replyto/addnumbers
2.WS-Addressing是如何传输数据的

我们在上面谈了,为什么需要WS-Addressing协议。下面我们来谈一谈WS-Addressing是如何传输数据的

WS-Addressing协议通过在SOAP消息的header中加入数据的方式来传送数据。具体的传送方法有如下两种:

1)Endpoint Reference

2)Message Addressing Properties


我们可以打个最简单的比方来解释上面两种技术,如果南京的小李要寄信给上海的小王,那么Message Addressing Properties就好像信封的格式(比如什么地方写邮编,什么地方写地址),而Endpoint Reference就好像信封上面具体的邮编,地址的内容


<s:Envelope xmlns:s="..." xmlns:wsa="..."><s:Header><wsa:Action>http://skonnard.com/SubmitClaim</wsa:Action><wsa:To>http://skonnard.com/Claims/Submit.asmx</wsa:To><wsa:From><wsa:Address>http://skonnard.com/main/sub.asmx</wsa:Address><wsa:ReferenceProperties><c:PatientProfile>123456</c:PatientProfile><c:CarrierID>987654</c:CarrierID></wsa:ReferenceProperties></wsa:From><wsa:ReplyTo><wsa:Address>http://skonnard.com/resp/resp.asmx</wsa:Address><wsa:ReferenceProperties><c:PatientProfile>123456</c:PatientProfile><c:CarrierID>987654</c:CarrierID></wsa:ReferenceProperties></wsa:ReplyTo><wsa:FaultTo><wsa:Address>http://skonnard.com/fault/err.asmx</wsa:Address><wsa:ReferenceProperties><c:PatientProfile>123456</c:PatientProfile><c:CarrierID>987654</c:CarrierID></wsa:ReferenceProperties></wsa:FaultTo></s:Header><s:Body xmlns:c="http://example.org/claims"><c:SubmitClaim> ... </c:SubmitClaim></s:Body></s:Envelope>

?

3.WS-Addressing都传输了什么数据

最后我们来谈一谈WS-Addressing到底能传输什么数据的?



读书人网 >编程

热点推荐