Thursday, November 18, 2010

How to implement transaction in WCF client

Here we see how to consume two wcf service from wcf client !

Create a WCF Service :

using System.ServiceModel;
namespace ACWCF
{ [ServiceContract]
public interface ITranService

void UpdateData();

// Implement the interface
public class TranService : ITranService
[OperationBehavior(TransactionScopeRequired = true)]
public void UpdateData()
SqlConnection objConnection = new SqlConnection("MyConnectionString");
SqlCommand objCommand = new SqlCommand("insert into Customer(CustomerName,CustomerCode) values('sss','sss')", objConnection);

// Assuming we are aware of hosting the service on IIS .. so i am not talking about the web.config part of it .

Now lets create a client to consume multiple wcf service

// this is how wcf client can consume multiple wcf service.
using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required))
//ServiceReference1.Service1Client obj = new ServiceReference1.Service1Client();
//ServiceReference2.Service1Client obj1 = new ServiceReference2.Service1Client();

catch (Exception ex)

A great article can be seen on

another good wcf clip can be seen at:

No comments:

ETG Consultancy

Web Designing Development Analysis & Promotion
Asp.Net 2.0 SQL WWF WCF SEO Marketing Ajax JQuery NHibernate MVC