I know that "a new transaction" can be started from a web method by simply
using an attribute
"[System.Web.Services.WebMethod(TransactionOption=Tr ansactionOption.RequiresNew)]
I guess the assumption here is that if the web method returns normally, the
transaction is automatically committed. Likewsie, if an exception throws, the
transaction is automatically aborted.
However, there are business scenarios under which I want to explicitly abort
the transaction in my web method. I heard this can be achieved with
"ContextUtil.SetAbort()". Since the web method is in a class that derives
from "System.Web.Services.WebServiceand" and that the same class cannot also
be derived from ServicedComponent (no multiple class inheritance supported in
..NET), is this possible? Maybe this is not relevant but when I call
ContextUtil.SetAbort() explicitly, I get an error "There is no MTS object
context".
I'd really appreciate help.
Here's my code (I get the "No MTS" error after the first occurence of
ContextUtil.SetAbort() in this code)
public class Gateway : System.Web.Services.WebService
{
public Gateway()
{
InitializeComponent();
}
[WebMethod(TransactionOption = TransactionOption.RequiresNew)]
[TraceExtensionAttribute(Filename="InsertCRPReportW ithTransaction.log")]
private XmlNode InsertCRPReportWithTransaction(string
strXMLParameters,string strCRPPivotalSystemName,string strCRPReportASR,string
strCRPReportASRMethodName)
{
const string WEBMETHODNAME="InsertCRPReportWithTransaction";
const string CLIENT_FAULTCODE="CLIENT";
XmlNode ndToReturn = null;
string strXMLReturnASR=string.Empty;
try
{
//call a work-horse component that does DB writes
if (strStatus=="FAILURE")
{
//Error occurred after this statement - There is no MTS object
context
ContextUtil.SetAbort();
}
ContextUtil.SetComplete();
}
//Various Catch blocks here
catch (XmlException xmlEx)
{
ContextUtil.SetAbort();
//release resources etc.
}
catch (PivotalWS.PIVOTALWSException exPIVOTALWS)
{
ContextUtil.SetAbort();
//release resources etc.
}
catch (Exception ex)
{
ContextUtil.SetAbort();
//release resources etc.
}
}
Thanks for your help.