Hello Dan,
why you don't create a custom compensator that you can incorporate in
your transactions of ServiceA? By using this, if a task/process in
ServiceB fails, it aborts the transaction that contains the serviceB
task (this is ServiceA).
Check the following links...
http://msdn2.microsoft.com/en-us/library/8xkdw05k.aspx
There is another way (probably easier) involving COM+ .
Let's say ServiceA has a method MethodA and ServiceB has a method
MethodB ... with code similar to the following you can achieve the same
functionality...
public void MethodA() {
try {
int result = serviceB.MethodB();
if (result<0){
ContextUtil.SetAbort();
}
else{
ContextUtil.SetComplete();
}
}
catch (Exception eX) {
ContextUtil.SetAbort();
}
}
This requiers ServiceA and ServiceB to be COM+ component in order to
take advandage of the provided COM+ services and marked as
Transaction.Support/Required (it depends on how you invoke the
methods).
So, when MethodA is executed a transaction begins. Inside that
transaction you call methodB which will be enlisted in the current
transaction. From inside methodB you can call ContextUtil.SetAbort() to
mark the transaction as failed, but you can also mark the transaction
as failed from MethodA (depending probably on the MethodB result). In
that way, when the method completes (and depending on the ContextUtil
votes, the transaction will either be commited, or rollbacked).
By using COM+ you have great flexibility regarding the
deployment/configuration of your application, so the distributed part
should not pose a serious issue.
I hope it helped
Regards
Tasos
Dan Kelley wrote:
I have 2 services, ServiceA and ServiceB. Certain user driven functions
require ServiceA to perform some DB tasks, before sending a request to
ServiceB to perform some additional tasks. If ServiceB fails to execute the
request, I would like ServiceA to rollback its changes. ServiceA and ServiceB
are located on 2 different servers on the same network.
I am struggling to find resources that cover this scenario. most articles
that discuss distributed transactions cover the scenario where 1 service
needs to update multiple data sources within a transaction.
Does anyone have any experience of handling this scenario? If so, could you
throw me a few pointers or any links you may have that can help.
Thanks
Dan