This topic covers using .NET WCF flowed transactions with SOAtest.
SOAtest and .NET WCF Flowed Transactions
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
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:
- WS Transaction Flow: http://msdn.microsoft.com/en-us/library/ms752261.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.
- How to enable network DTC access in Windows Server 2003: http://support.microsoft.com/kb/817064/en-us
- How to troubleshoot MS DTC firewall issues: http://support.microsoft.com/kb/306843/en-us
Configuring the Test Suite
Invoking several Web service operations within the scope of a transaction requires configuring a
TransactionScope object. Take the following C# code snippet:
In SOAtest, an equivalent test suite would be structured as follows:
- Extension Tool 1: Create Transaction Scope
- XML Data Bank: propagation token
- Tool 1: add(1,2)
- Tool 2: add(2,3)
- Extension Tool 2: Complete Transaction
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:
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:
The WcfUtil methods and corresponding .NET API are described below:
int webtool.soap.wcf.WcfUtil.createTransactionScope(int scopeOption, int isolationLevel, int scopeTimeout)
See TransactionScopeOption Enumeration:
Can be one of the following:
See IsolationLevel Enumeration:
Can be one of the following:
- The timeout of the TransactionScope in ms.
An ID that can be used to reference the TransactionScope.
The Base64 encoding of the propagation token for the current transaction.
- The id returned by WcfUtil.createTransactionScope()
Configuring Transaction Headers
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:
To add the above header to tool 1, complete the following:
- Select the SOAP Header tab from within a tool’s Request tab.
- Click the Add button within the SOAP Header tab. The Add New SOAP Header dialog displays.
- Select Custom from the Add New SOAP Header dialog and click the OK button. A new row is added to the SOAP Header tab.
- Double-click the new row in the SOAP Header tab. An Edit dialog displays.
Paste the following sample
OleTxTransactionSOAP header into the Literal/XML text field of the Edit dialog:
- Select Form XML from the Views drop down box of the Edit dialog, and click Yes to override Form XML values with Literal XML values.
- In the Form XML view, select the PropagationToken element, then select the Parameterized option for the element's value. This will allow you to choose the XML Data Bank column containing the propagation token.
- Click the OK button.
WS-Atomic Transaction Headers
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:
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.