BizTalk and web service transactions - how to do that?

Hi all!

I have an orchestration which calls two web services (they are further performing some database operations).

I have managed to use Transaction Internet Protocol and TipUrl to get transactions and rollback working for web services, when I call them from a C# application. But when trying to send TIPUrl as a part of a message from a BizTalk orchestration I get "Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.BizTalk.Agent.Interop.IBTMessageBatchEx'." error.

So is there any way to get TIP working from an orchestration or maybe I need completely different approach to get transactions and rollback working for webservices and BizTalk?

Thanks.

[872 byte] By [midix] at [2008-1-10]
# 1

Hi Midix,

Actually, the picture in my mind is not clear.

1) Can you give some more detailed (if it is appropriate) about the scenario?

2) How did you implement the orchestration?


3) What is LR transaction and compensation logic like?

Thanks


- Ibrahim DURMUS
http://www.ibrahimdurmus.com
http://blogs.msdn.com/ibrahim

# 2
Thanks, ibrahim durmus, for your interest. I 'll try to explain the problem deeper.

At first I read some info about BizTalk orchestartions and found out that Atomic scope does not guarantee full transactions support if not used directly with MSDTC. And I think that my case is really far from direct MSDTC connectivity.
I am using 2 web services. One is trying to save (or update) one kind of documents in a MS SQL database, the other is doing the same with other kind of documents in other database. Tha task is: if the second of web services fails to save (or update) the document, then the first one should roll back (if it succeeded with saving). And if the first fails, then the second should not try to save anything at all.

The first thing I studied was this "Using TIP (Transaction Internet Protocol) to Enlist Web Services into COM+ Distributed Transactions":
http://www.codeproject.com/csharp/complus_tip.asp

and I got it working nice from a simple C# Application - my web services act exactly the way I need.

Then I tried to implement it in an orchestration the same way. I thought that orchestration should not know anything about the transaction process behind those web services. All the transactions are controlled by a class TransactionController from the example in the article. So I registered my TransactionController.dll in GAC, made a reference to the dll and made a simple orchestration which:
receives a multipart message with two dokuments
then comes Atomic scope with a variable TC of my TransactionController class

orch. calls TC.BegioTransaction();
orch. constructs a message (the first document to save) and adds TC.TipUrl as a part of message;
orch. sends a message to the first web service through SOAP prot;
orch. constructs a message (the second document to save) and adds TC.TipUrl as a part of message;
orch. sends a message to the second web service through SOAP prot;
orch. calls TC.EndTransaction();
Atomic scope ends.
orch. receives response from the first web service;
orch. receives response from the second web service.

I am using System.Diagnostics.Trace.WriteLine to output messages from an orch. and DebugView utility to see those messages. So I monitored debug messages that I put in the orch. and I saw that TIPUrl is fine, it is filled with data. The first message was constructed successfully. Then comes the Send shape. ... and all freezes and event log says:

"An error occurred that requires the BizTalk service to terminate. The most common causes are the following:
1) An unexpected out of memory error.
OR
2) An inability to connect or a loss of connectivity to one of the BizTalk databases.
The service will shutdown and auto-restart in 1 minute. If the problematic database remains unavailable, this cycle will repeat.

Error message: Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.BizTalk.Agent.Interop.IBTMessageBatchEx'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{6C90EC04-4918-11D3-A242-00C04F60A533}' failed due to the following error: Interface not registered (Exception from HRESULT: 0x80040155).
Error source: Microsoft.BizTalk.Interop.Agent

BizTalk host name: BizTalkServerApplication
Windows service name: BTSSvc$BizTalkServerApplication "

and after that BizTalk host instance shuts off and starts again after a minute and gives the same error and so on until I terminate the orch.

However, if I run the orchestration without TC.BegioTransaction(); and TC.EndTransaction(); it runs fine, but TIPUrl is empty and that means - no transactions at all.

I googled a lot but got no idea what BizTalk needs to send TIPUrl to the web service. So I am stuck. But ithe solution seems to be so close - if it works from C# app then why it cannot work from orchestrations? Maybe it is somehow related to COM+ and how BizTalk uses COM+ ?

I would be grateful for any ideas.

Thanks.




midix at 2007-10-3 > top of Msdn Tech,BizTalk Server,BizTalk R2 General...
# 3
Please, look at the "Transactions Across BizTalk Server 2004"
http://msdn2.microsoft.com/en-us/library/ms942198.aspx
LeonidGaneline-MVP at 2007-10-3 > top of Msdn Tech,BizTalk Server,BizTalk R2 General...
# 4
Thanks for useful link. But it does not explain how to achieve rollback for web services.

Also I should mention that my two web services are implemented in a way that even if they fail to save / update data in the databases, the services do not fail themselves - they return a document with a designated status node.filled with "error".
The problem of the orchestartion is only to tell each web service that it is participating in some transaction and give it an identifier for the transaction.Tthat is when TIPUrl should work. But it does not and I cannot understand why. Maybe I need to publish or deploy or put into GAC or somehow else register the missing COM interface which makes BIzTalk restart its Host Instance. But I have no idea which interface is missing. Especially because everything works fine from a C# application.

Really confused.

midix at 2007-10-3 > top of Msdn Tech,BizTalk Server,BizTalk R2 General...
# 5

"Two new whitepapers have recently been authored and will be posted to MSDN shortly. These are full of key information on the primary issues customers may face when using the SQL and SOAP adapters with BizTalk Server.

They can be found at:...

Best Practices for the SQL Adapter

http://download.microsoft.com/download/5/0/f/50f397a7-13c7-4807-bd51-66db5f5b0908/best%20practices%20for%20the%20sql%20adapter.doc

Sample Design Patterns for Consuming and Exposing Web Services from an Orchestration http://download.microsoft.com/download/1/6/9/16968441-c6c8-4bd0-9410-5f4014bc61f0/sampledesignorch.doc

" (it's from http://blogs.msdn.com/csdcustomerexperience/archive/2007/07/11/sql-and-soap-adapter-whitepapers-published.aspx)
LeonidGaneline-MVP at 2007-10-3 > top of Msdn Tech,BizTalk Server,BizTalk R2 General...
# 6

Hi again Midix:

Thanks for the error log. It says "Interface not registered (Exception from HRESULT: 0x80040155)."
Probably, Biztalk Message Agent faces with a problem however it is not easy to say
the reason on top of head.

Before investigating further, let me ask you a question:

What was the reason that you don't prefer to use LR transaction.
I know you didn't prefer for Atomic Scopes but I wonder the reason of LR?

LR Transactions Info : http://msdn2.microsoft.com/en-us/library/aa560028.aspx


- Ibrahim DURMUS
http://www.ibrahimdurmus.com
http://blogs.msdn.com/ibrahim

# 7
Hi all.

I cannot use LR because then I get an error:
" a non-serializable object type 'MyTransactions.TransactionController TC' can only be declared within an atomic scope or service"
and I need that TC variable to pass TC.TIPUrl to my web services.
It is strange to see that the ""Interface not registered" error shows up at the moment when I send the message with TIPUrl. Till then everything is fine - TC construction, call of BeginTransaction(), getting TIPIUrl. So BizTalk needs that unknown interface at the moment of sending TIPUrl. But how to find out what is that interface?

midix at 2007-10-3 > top of Msdn Tech,BizTalk Server,BizTalk R2 General...