Dear All,
I am using VS2008
I was trying to use transaction feature of WCF.
I created two service and used in client side in transactionscope but it is not rollback.
Please advice .Code used is given below
I created two wcf method as
Interface as
[OperationContract]
[TransactionFlow(TransactionFlowOption.Allowed)]
void UpdateData();
Implemented as
public void UpdateData()
{
//using (TransactionScope scope = new TransactionScope())
//{
throw new Exception();
SqlConnection objConnection = new SqlConnection(strConnection);
objConnection.Open();
SqlCommand objCommand = new SqlCommand("insert into Customer(CustomerName,CustomerCode) values('IMRAN','AZIZ')", objConnection);
objCommand.ExecuteNonQuery();
objConnection.Close();
//}
}
similarly the other service.
And define binding as
<system.serviceModel>
<client/>
<services>
<service name="WcfService2.Service1" behaviorConfiguration="WcfService2.Service1Behavior">
<endpoint address="" bindingConfiguration="TransactionalBind" binding="wsHttpBinding" contract="WcfService2.IService1">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="TransactionalBind" transactionFlow="true"/>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="WcfService2.Service1Behavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
and used on clint side as
using (TransactionScope ts = new TransactionScope(TransactionScopeOption.RequiresNew ))
{
try
{
ServiceReference1.Service1Client obj = new ServiceReference1.Service1Client();
obj.UpdateData();
ServiceReference2.Service1Client obj1 = new ServiceReference2.Service1Client();
obj1.UpdateData();
ts.Complete();
}
catch (Exception ex)
{
ts.Dispose();
}
}
But it execute both the method when there is error on second method it does not rollback .
Thank you