Kevin Li

突破.net极限

导航

基于WS-AtomicTransaction标准的WCF远程分布式事务(二)

Posted on 2007-05-26 23:39  Kevin Li  阅读(3570)  评论(1编辑  收藏  举报
上一篇文章“基于WS-AtomicTransaction标准的WCF远程分布式事务”写了如何配置MSDTC支持WS-AT协议和写了一段WCF代码使用WS-AT协议。但是WCF是如何支持WS-AT协议的呢?
通过用WCF本身的Log功能或者用smsniff监控一下网络消息,就可以知道MachineA和MachineB传递的消息和一般的WCF程序不一样,消息遵循了WS-AtomicTransaction工业标准。下面是监控到的一部分消息内容:
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
<a:Action s:mustUnderstand="1">http://tempuri.org/ICustomerService/GetCustomerName</a:Action>
<a:MessageID>urn:uuid:0cc037a3-7c3c-4b0e-bdf8-9856ea8b0061</a:MessageID>
<a:ReplyTo>
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
</a:ReplyTo>
<a:To s:mustUnderstand="1">http://li/CustomerService</a:To>
</s:Header>
<s:Body>
<GetCustomerName xmlns="http://tempuri.org/">
<customerID>1</customerID>
</GetCustomerName>
</s:Body>
</s:Envelope>

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
<a:Action s:mustUnderstand="1">http://tempuri.org/IOrderService/UpdateOrderStatus</a:Action>
<a:MessageID>urn:uuid:bf31aa58-8421-41d8-94e3-377a1235c64c</a:MessageID>
<a:ReplyTo>
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
</a:ReplyTo>
<CoordinationContext s:mustUnderstand="1" xmlns="http://schemas.xmlsoap.org/ws/2004/10/wscoor" xmlns:mstx="http://schemas.microsoft.com/ws/2006/02/transactions">
<wscoor:Identifier xmlns:wscoor="http://schemas.xmlsoap.org/ws/2004/10/wscoor">urn:uuid:89ebe490-88fe-45d8-a931-bc3f88612693</wscoor:Identifier>
<Expires>58880</Expires>
<CoordinationType>http://schemas.xmlsoap.org/ws/2004/10/wsat</CoordinationType>
<RegistrationService>
<Address xmlns="http://schemas.xmlsoap.org/ws/2004/08/addressing">https://liweiguang:1443/WsatService/Registration/Coordinator/</Address>
<ReferenceParameters xmlns="http://schemas.xmlsoap.org/ws/2004/08/addressing">
<mstx:RegisterInfo>
<mstx:LocalTransactionId>89ebe490-88fe-45d8-a931-bc3f88612693</mstx:LocalTransactionId>
</mstx:RegisterInfo>
</ReferenceParameters>
</RegistrationService>
<mstx:IsolationLevel>0</mstx:IsolationLevel>
<mstx:LocalTransactionId>89ebe490-88fe-45d8-a931-bc3f88612693</mstx:LocalTransactionId>
<PropagationToken xmlns="http://schemas.microsoft.com/ws/2006/02/tx/oletx">AQAAAAMAAACQ5OuJ/ojYRakxvD+IYSaTAAAQAAAAAACUAAAAAP///4LS6HlX0uh5clisZ9oT8nlyWKxnYOb2A+wN+QMIXh8ApOX2A2I1YmExNmU2LTc1ODEtNDkyYi04YWE3LThkNjQwZWU1NTMwNQCp/EMKAAAAZM1kzSEAAABMSVdFSUdVQU5HAHcYAAAATABJAFcARQBJAEcAVQBBAE4ARwAAAHAuAQAAAAEAAAApAAAAdGlwOi8vbGl3ZWlndWFuZy5hc2lhcGFjaWZpYy5ocHFjb3JwLm5ldC8Agd0=</PropagationToken>
</CoordinationContext>
<a:To s:mustUnderstand="1">http://li/OrderService</a:To>
</s:Header>
<s:Body>
<UpdateOrderStatus xmlns="http://tempuri.org/">
<orderID>4400000000000001</orderID>
<orderStatus>1</orderStatus>
</UpdateOrderStatus>
</s:Body>
</s:Envelope>

 第一段消息是没有使用事务的方法调用的消息,第二段是使用WS-AT事务的方法的调用的消息。
从第二段消息可以看出,明显加入了WS-Coordination、WS-Transaction、WS-Addressing的内容。对比一下IBM WAS生成的WS-AT消息(使用 WS-AtomicTransaction 和 JTA 的分布式事务:http://www.ibm.com/developerworks/cn/webservices/ws-wsat/ ),除了协议中自定义部分“ReferenceProperties”,其他基本上是一致的。
也可以看出来,WCF很好的实现了WS-AT协议。下一步打算测试一下WCF WS-AT和java web service的互操作性(虽然Sun声明它的产品和微软的WCF具有很好的互操作性http://www.infoq.com/cn/news/2007/04/sunmsftwsat),呵呵

如果修改一下配置文件,使用OletxTransaction,而不是WS-AT的话,就得到不一样的消息:

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
<a:Action s:mustUnderstand="1">http://tempuri.org/ICustomerService/Update</a:Action>
<a:MessageID>urn:uuid:08dd935a-2e77-4bd7-bad1-73fc65555d9f</a:MessageID>
<a:ReplyTo>
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
</a:ReplyTo>
<OleTxTransaction s:mustUnderstand="1" b:Expires="59904" xmlns="http://schemas.microsoft.com/ws/2006/02/tx/oletx" xmlns:b="http://schemas.xmlsoap.org/ws/2004/10/wscoor">
<PropagationToken>AQAAAAMAAADlvokJX0c9R6q9uvZOpBv+AAAQAAAAAACUAAAAAP///4LS6HlX0uh5clisZ9oT8nlyWKxn6OUJBBwOqwOgQCAALOUJBGI1YmExNmU2LTc1ODEtNDkyYi04YWE3LThkNjQwZWU1NTMwNQCp/EMKAAAAZM1kzSEAAABMSVdFSUdVQU5HAHcYAAAATABJAFcARQBJAEcAVQBBAE4ARwAAAHAuAQAAAAEAAAApAAAAdGlwOi8vbGl3ZWlndWFuZy5hc2lhcGFjaWZpYy5ocHFjb3JwLm5ldC8Agd0=</PropagationToken>
</OleTxTransaction>
<a:To s:mustUnderstand="1">http://li/CustomerService</a:To>
</s:Header>
<s:Body>
<Update xmlns="http://tempuri.org/">
<customerID>1</customerID>
</Update>
</s:Body>
</s:Envelope>