Hi,
I have got the following scenario...
We follow Service Oriented architecture. There are 2 webmethods say Webmethod1 and Webmethod2 where I call the stored procedures. I used transactions in each of the webmethods. Webmethod2 should be executed only after Webmethod1.
In the front end, I call Webmethod1 and if it succeeds, I will call Webmethod2.
The business rule is
- if either of the webmethods fail, both the stored procedures should rollback.
ie. if webmethod2 rollsback, then webmethod1 should "also rollback".
eg.
bool chk = false;
chk = webmethod1(); //commits stored procedure1 if succeeds
if (chk)
{
chk = webmethod2(); //commits stored procedure2 if succeeds
if (!chk) //if error
{
//Stored procedure executed in webmethod1 should be rollback
//which becomes a problem
}
}
This becomes the problem. As I commit the stored procedure in Webmethod1, there is no way to rollback if there is an error in Webmethod2. I cannot combine these 2 stored procedures into one webmethod because "not always webmethod2 is called after webmethod1". So, the solution I could think of is to use nested transactions.
Please advice me on how to use the nested transactions. I have got 4-5 webmethods which have to be called in sequence (not combinable into 1 method) and if anything fails, all the webmethods have to be rolledback.
Thanks,
Jon