How to enable transaction in Web Service ?

Please follow below steps to enable transaction in Web Service :
1.Add a reference to System.EnterpriseServices.dll.
2.Add the System.EnterpriseServices namespace to the XML Web service
using System.EnterpriseServices;

3.Use the TransactionOption property of the WebMethod attribute, as shown below:


public class Service1 : System.Web.Services.WebService

{

[System.Web.Services.WebMethod(

TransactionOption=TransactionOption.RequiresNew)]

public string DoSomethingTransactional()

{

// The transaction was successful...

ContextUtil.SetComplete();

return ContextUtil.TransactionId.ToString();

}

}

No comments:

Popular Posts