WCF Transaction Configuration Steps

Step 1) Contact được thiết lập thuộc tính:

[ServiceContract]
public interface IService1
{
[OperationContract, TransactionFlow(TransactionFlowOption.Mandatory)]
bool PerformCreditTransaction(string creditAccountID, double amount);

Step 2)
Lớp cài đặt dịch vụ được thiết lập như sau:

[OperationBehavior(TransactionScopeRequired = true)]
public bool PerformCreditTransaction(string creditAccountID, double amount)

Step 3) cấu hình web.config

<services>
<service name=”WcfServiceTransaction.Service1″ behaviorConfiguration=”WcfServiceTransaction.Service1Behavior”>
<endpoint address=”” binding=”wsHttpBinding” contract=”WcfServiceTransaction.IService1″ bindingConfiguration=”httpBinding”>
<identity>
<dns value=”localhost”/>
</identity>
</endpoint>
<endpoint address=”mex” binding=”mexHttpBinding” contract=”IMetadataExchange”/>
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name=”httpBinding” transactionFlow=”true”/>
</wsHttpBinding>
</bindings>

Step 4) Client

Sử dụng TransactionScope và ts.Complete()

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s