This topic covers using .NET WCF flowed transactions with SOAtest.
Sections include:
SOAtest can initiate flowed transactions using WS-Atomic Transaction or the Microsoft OleTransactions protocol. Flowed transactions can be used when the service endpoint's binding configuration has transactionFlow="true"
and either transactionProtocol="OleTransactions"
or transactionProtocol="WSAtomicTransactionOctober2004"
.
If the operation contract for the Web service uses the TransactionFlow
attribute with the TransactionFlowOption.Allowed
property, then enabling transactions in SOAtest is optional and does not require any extra test configuration.
However, if the operation contract is using the TransactionFlowOption.Mandatory
property, then transactions are required and the test suite must be configured to initiate a flowed transaction. For general information about WCF flowed transactions, see the following:
TransactionFlowAttribute: http://msdn.microsoft.com/en-us/library/system.servicemodel.transactionflowattribute.aspx
TransactionFlowOption: http://msdn.microsoft.com/en-us/library/system.servicemodel.transactionflowoption.aspx
The above WS Transaction Flow MSDN article explains what is required to configure a WCF web service client to initiate a flowed transaction. The steps necessary to configure transactions in SOAtest are similar or analogous to what is described in this article. It is highly recommended for users to read the WS Transaction Flow article in order to first understand the basic concepts behind transactions in WCF.
The Microsoft Distributed Transaction Coordinator (MSDTC) must be configured correctly on the machine running SOAtest, as well as the machine hosting the Web service. The MSDN WS Transaction Flow article has instructions for configuring MSDTC and how to configure the Windows firewall to allow DTC. Here are a few other articles that may be useful when configuring MSDTC.
Invoking several Web service operations within the scope of a transaction requires configuring a TransactionScope
object. Take the following C# code snippet:
CalculatorClient client = new CalculatorClient("transactionEnabledEndpoint");using (TransactionScope tx = new TransactionScope(TransactionScopeOption.Required)) { client.add(1, 2); client.add(2, 3); tx.Complete(); } client.Close(); |
In SOAtest, an equivalent test suite would be structured as follows:
In the test suite above, Extension Tool 1 is needed to create the TransactionScope
object and to get the propagation token for the current transaction. The propagation token is then put into an XML Data Bank because it will be needed later by the tools (described later). Here is sample Jython code that can be used for Extension Tool 1:
from webtool.soap.wcf import *; from soaptest.api import *; def createTransaction(input, context): id = WcfUtil.createTransactionScope(WcfUtil.TRANSACTION_SCOPE_OPTION_REQUIRED, WcfUtil.ISOLATION_LEVEL_SERIALIZABLE, 60000) context.put("MY_TRANSACTION_ID", id) token = WcfUtil.getCurrentPropagationToken() return SOAPUtil.getXMLFromString([token]) |
The Extension Tool 2 in the test suite is used to complete the transaction. This Extension tool is doing the equivalent of tx.Complete() in the above C# code snippet. Here is the Jython code for Extension Tool 2:
from webtool.soap.wcf import *; def endTransaction(input, context): id = context.get("MY_TRANSACTION_ID") WcfUtil.completeTransactionScope(id) |
The WcfUtil methods and corresponding .NET API are described below:
scopeOption
See TransactionScopeOption Enumeration: http://msdn.microsoft.com/en-us/library/system.transactions.transactionscopeoption.aspx
Can be one of the following:
isolationLevel
See IsolationLevel Enumeration: http://msdn.microsoft.com/en-us/library/system.transactions.isolationlevel.aspx
Can be one of the following:
scopeTimeout
An ID that can be used to reference the TransactionScope.
The Base64 encoding of the propagation token for the current transaction.
transactionScopeRef
The tools each need to have a SOAP header that contains the propagation token. This propagation token comes from the XML Data Bank chained to the first Extension Tool test that was described earlier. The type of SOAP header that is needed depends on the transaction protocol.
For OleTransactions, a OleTxTransaction SOAP header is needed. For convenience, here is a sample OleTxTransaction
SOAP header:
<OleTxTransaction b:Expires="59904" s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2006/02/tx/oletx" xmlns:b="http://schemas.xmlsoap.org/ws/2004/10/wscoor" xmlns:s="http://www.w3.org/2003/05/soap-envelope"> <PropagationToken></PropagationToken> </OleTxTransaction> |
To add the above header to tool 1, complete the following:
Paste the following sample OleTxTransaction
SOAP header into the Literal/XML text field of the Edit dialog:
<OleTxTransaction b:Expires="59904" s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2006/02/tx/oletx" xmlns:b="http://schemas.xmlsoap.org/ws/2004/10/wscoor" xmlns:s="http://www.w3.org/2003/05/soap-envelope"> <PropagationToken></PropagationToken> </OleTxTransaction> |
For WS-Atomic Transaction, a CoordinationContext
SOAP header is needed instead. Similar to the OleTxTransaction
header, the PropagationToken
element must be parameterized to include the propagation token from the XML Data Bank. For convenience, here is a sample CoordinationContext SOAP header:
<CoordinationContext s:mustUnderstand="1" xmlns="http://schemas.xmlsoap.org/ws/2004/10/wscoor" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:mstx="http://schemas.microsoft.com/ws/2006/02/transactions" xmlns:s="http://www.w3.org/2003/05/soap-envelope"> <wscoor:Identifier xmlns:wscoor="http://schemas.xmlsoap.org/ws/2004/10/wscoor"></wscoor:Identifier> <Expires>59904</Expires> <CoordinationType>http://schemas.xmlsoap.org/ws/2004/10/wsat</CoordinationType> <RegistrationService> <Address xmlns="http://schemas.xmlsoap.org/ws/2004/08/addressing">https://hostname/WsatService/Registration/Coordinator/Disabled/</Address> <ReferenceParameters xmlns="http://schemas.xmlsoap.org/ws/2004/08/addressing"> <mstx:RegisterInfo> <mstx:LocalTransactionId></mstx:LocalTransactionId> </mstx:RegisterInfo> </ReferenceParameters> </RegistrationService> <mstx:IsolationLevel>0</mstx:IsolationLevel> <mstx:LocalTransactionId></mstx:LocalTransactionId> <PropagationToken xmlns="http://schemas.microsoft.com/ws/2006/02/tx/oletx"></PropagationToken> </CoordinationContext> |
To add the above header to tool 2, follow the same procedure as outlined for tool 1, but instead paste the above CoordinationContext SOAP header into the Edit dialog.