Thursday, August 19, 2010

Exception handling in BizTalk WCF-LOB adapter

Hi, 
Recently I've received an exception in the event viewer when trying to access an Oracle procedure via WCF-OracleDb adapter: 


As you can see, I'm getting an ORA-XXXXX exception and the LOB adapter is throwing Microsoft.ServiceModel.Channels.Common.TargetSystemException. That means there was a problem executing the operation on the ERP. 


But how do I catch this kind of exception in my orchestration ? 
First of all, it's important to set the "Delivery Notification" property on the port configuration to "Transmitted" (In order to notify the orchestration in case of transmission failure). 


The second part of catching the exception is not quite a straight-forward matter. 
I've tried to catch Microsoft.ServiceModel.Channels.Common.TargetSystemException exception in my orchestration (after adding references to Microsoft.ServiceModel.Channels and System.ServiceModel) but it doesn't seem to work (Because you can only handle SOAP exceptions thrown from the port). 
Second shot was to try catch a "General Exception". We use it to catch exceptions which are not derived from System.Exception. That's the reason why you can't get an exception object or any details on the exception. 
So I did managed to catch the exception, but still wanted to get information on the exception. 
Third and last shot! I've attached to the BizTalk service process: "BTSNTSVC.exe" using Microsoft Visual Studio, and ran the orchestration in order to get this exception again.

This way I got more accurate information on the exception rather than reading the trace log in the event viewer
-->The exception type is: 'Microsoft.XLANGs.Core.XlangSoapException'. 
When you look for this type in the MSDN, you can see it derived from System.Exception. 
BUT, as mentioned before - you can't catch System.Exception because it's thrown from the port and (or any other classes it derived from) it isn't a SOAP exception. 
In conclusion - you have to catch 'Microsoft.XLANGs.Core.XlangSoapException'. 
I've wanted to configure this as the 'Exception Object Type' in the catch exception scope of my orchestration, but couldn't find it on the .NET Exceptions list, so I had to do a little trick here: 
1. I've added a catch scope with 'System.Exception' type (Basically, you can choose whatever type you want). 
2. I've opened the orchestration .odx file using notepad, and modified the XLANG code by 
changing each occurrence of 'System.Exception' to 'Microsoft.XLANGs.Core.XlangSoapException':

-->

Caught it!

Don't let those exceptions slip away :), 
Ohad.

1 comment:

Thank you Blogger, hello Medium

Hey guys, I've been writing in Blogger for almost 10 years this is a time to move on. I'm happy to announce my new blog at Med...