基于WS-AtomicTransaction标准的WCF远程分布式事务(二)
2007-05-26 23:39
357 查看
上一篇文章“基于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>
通过用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>
相关文章推荐
- 基于WS-AtomicTransaction标准的WCF远程分布式事务(一)
- 基于WS-AtomicTransaction标准的WCF远程分布式事务(补充)
- WCF分布式安全开发实践(8):消息安全模式之用户名身份验证:Message_UserName_WSHttpBinding
- WCF分布式安全开发实践(11):消息安全模式之Certificate身份验证:Message_Certificate_WSHttpBinding
- 分布式事务之——tcc-transaction分布式TCC型事务框架搭建与实战案例(基于Dubbo/Dubbox)
- 小测试,WCF分布式事务的用法以及回滚条件 .
- 基于SpringCloud的分布式事务框架(LCN)
- 架构设计实践:基于WCF大型分布式系统
- 基于可靠消息的分布式事务错误处理
- 基于WCF大型分布式系统的架构设计
- 基于MySQL的分布式事务控制方案(C#实现)
- 从远程服务器数据库中同步数据到本地数据库 sql server 2008 开启分布式事务
- wcf 分布式事务实践
- WCF分布式安全开发实践(11):消息安全模式之Certificate身份验证:Message_Certificate_WSHttpBinding
- WCF分布式安全开发实践(12):消息安全模式之自定义X509证书验证:Message_CustomX509Certificate_WSHttpBinding
- 分布式事务、基于Best Efforts 1PC模式的事务
- 分布式事务之——tcc-transaction分布式TCC型事务框架搭建与实战案例(基于Dubbo/Dubbox)
- 谈谈分布式事务之二:基于DTC的分布式事务管理模型[上篇]
- 采用Best effort 1pc + 回滚补偿机制实现的一个distributed transaction (分布式事务框架).基于dubbo rpc服务上实现。
- WCF分布式安全开发实践(12):消息安全模式之自定义X509证书验证:Message_CustomX509Certificate_WSHttpBinding