基于WS-AtomicTransaction標(biāo)準(zhǔn)的WCF遠(yuǎn)程分布式事務(wù)(二)
Posted on 2007-05-26 23:39 Kevin Li 閱讀(3589) 評論(1) 收藏 舉報
上一篇文章“基于WS-AtomicTransaction標(biāo)準(zhǔn)的WCF遠(yuǎn)程分布式事務(wù)”寫了如何配置MSDTC支持WS-AT協(xié)議和寫了一段WCF代碼使用WS-AT協(xié)議。但是WCF是如何支持WS-AT協(xié)議的呢?
通過用WCF本身的Log功能或者用smsniff監(jiān)控一下網(wǎng)絡(luò)消息,就可以知道MachineA和MachineB傳遞的消息和一般的WCF程序不一樣,消息遵循了WS-AtomicTransaction工業(yè)標(biāo)準(zhǔn)。下面是監(jiān)控到的一部分消息內(nèi)容:
<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>
<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監(jiān)控一下網(wǎng)絡(luò)消息,就可以知道MachineA和MachineB傳遞的消息和一般的WCF程序不一樣,消息遵循了WS-AtomicTransaction工業(yè)標(biāo)準(zhǔn)。下面是監(jiān)控到的一部分消息內(nèi)容:
<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> 第一段消息是沒有使用事務(wù)的方法調(diào)用的消息,第二段是使用WS-AT事務(wù)的方法的調(diào)用的消息。
從第二段消息可以看出,明顯加入了WS-Coordination、WS-Transaction、WS-Addressing的內(nèi)容。對比一下IBM WAS生成的WS-AT消息(使用 WS-AtomicTransaction 和 JTA 的分布式事務(wù):http://www.ibm.com/developerworks/cn/webservices/ws-wsat/ ),除了協(xié)議中自定義部分“ReferenceProperties”,其他基本上是一致的。
也可以看出來,WCF很好的實現(xiàn)了WS-AT協(xié)議。下一步打算測試一下WCF WS-AT和java web service的互操作性(雖然Sun聲明它的產(chǎn)品和微軟的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>
浙公網(wǎng)安備 33010602011771號