BizTalk Training – Handling Exceptions inside orchestration

Posted: October 26, 2009 in BizTalk
Tags: , , ,

Handling exceptions inside orchestration is the equivalent of doing a “catch { }” block in C#, of course there are some little differences, but the idea is the same.

General Exception Type

When we create New Exception Handler, in property “Exception Object Type combo, the only item in the list is ‘General Exception’:

Think of catching a “Generic Exception” as the equivalent of doing a “catch { }” block in C# with no exception declared. “General Exception” allows BizTalk to deal with any exception it may catch and re-throw, there’s no way to get the exception message at that point.

How can I get Exception Message

You can accomplish this by change the exception type to System.Exception or other type (System.Web.Services.Protocols.SoapException):

  • In “Exception Object Type” property select: <.NET Exception…>
  • In Artifact Type windows, select System.Exception

By selecting another type, you are able to define “Exception Object Name”, in this case “ex”, and then for getting the error message is just like C#: “ex.Message” or “ex.ToString()”.

Handling Delivery Failure Exception (using a request-response port)

There is a great post by Naveen Karamchetti about this; this is the key steps…

In order to catch an exception within your scope block in BizTalk while using a request-response port, you might have to do the following:

  • Set the retry-count to 0 on your physical request-response port which you use to bind.
  • Enable the flag Delivery Notification to ‘Transmitted’ on your logical request-response port within the orchestration.
  • Catch the “Microsoft.XLANGs.BaseTypes.DeliveryFailureException” exception and handle it as you’re please.

The Delivery Notification flag on the Send Port indicates that the orchestration must be NOTIFIED back, in case the message has not been received by the destination. Delivery Notification works only when the Retry Count set to 0. When a message cannot be delivered, a Delivery Failure Exception is raised and the exception needs to be handled by the Orchestration.

Handling and Throwing SOAP Exceptions from BizTalk

Similar to Delivery Failure, but in this case, we have to configure the Exception with “System.Web.Services.Protocols.SoapException”.

Note: remember to set the retry-count to 0.

To get error message, just: “ex.Detail.InnerText”

Download the example source code:

Handling Exceptions inside BizTalk Orchestrations (88.9 KB)
Microsoft | MSDN Code Gallery

 

Tags: BizTalk | Orchestration | Exceptions | Training

Comments
  1. Shine says:

    Hi, It is really nice to see your post. But I am a fresh newbie without any programming background. I have orchestration designed, I want to catch any kind of exception. I consume wcf-sql adapter to get stored procedure in SQL DB. Then I used file adapters to file-in, file-out, and file-Exception Messages. I put shapes into the scope, and chose a new exception handler, and gave it a name and .net type, system.exception. And defined a variable, System.Xml.XmlDocument type.
    I have tried so many times, but no working… can pass the right xml, but the error will only show in the biztalk admin console’s event log… Would you please help me? Give me some hints?

  2. Anonymous says:

    Hi Sandro,

    I’ve been benefit from your very resourceful and helpful blog for a while. Lately I ran into this post and associated links. I am unable to capture the Delivery Failure Exception. It seems “Delivery Failure Exception” will not be thrown in static request-response port, Did I miss something here?

    Thanks,
    Michael

    • Hi Michael,

      You have to go to Transport Advance Options tab on you Static Solicit-Response port, check the check box “Enable routing for failed messages” and set “Retry Count” value to “0”.

      On your logical request-response port (inside orchestration) you need to Enable the flag Delivery Notification to ‘Transmitted’

      • Anonymous says:

        Hi Sandro,

        Thanks for your prompt response. Yes, I did set physical and logical port as you indicated. However, the last “General Exception” handler catches the exception rather than the “Delivery Failure Exception” handler right above “General Exception”. Neither did System.SystemException catch it as well. I re-read Naveen’s post you provided and it seems to me that “Delivery Failure Exception” capturing mechanism only works for one way transport. I am not sure though, as I don’t have luck. Could it because the adapter difference between BizTalk 2006 R2 and latest version? What else I might be missing?

        Thanks,
        Michael

    • Did you set also scope Synchronized property to “True”? You must use a Synchronized scope.

      • Anonymous says:

        Yes, I did. The 1st exception handler that I set the exception object type to “Microsoft.XLANGs.BaseTypes.DeliveryFailureException ” did not caught the Delivery Failure Exception. After poke around, the SOAP Exception set to object type “System.Web.Services.Protocols.SoapException ” that I put right after the “Delivery Failure Notification” handler caught the exception instead.

        One of the MSDN BizTalk 2006 R2 product document that I have found seems indicating that as well, saying “This applies only to one-way operations; failure in two-way (request-response) operations results in a SoapException (negative acknowledgement) even without the port attribute being set.”. However, I am not sure if this has been changed in newer version of BizTalk Server after 2006 R2 though.

        If interested, the MSDN URL is: http://msdn.microsoft.com/en-us/library/aa559388%28v=bts.20%29.aspx

        With several complex orchestrations chained to automate the processes, and each orchestration with a couple of Web Services calls, trying to catch the system/environment issue in transport layer(e.g. web service down, network issues) and react properly instead of wait for suspension, aside from SOAP Exception what’s the best practice of exception handling structure in chained orchestration you would recommend?

        Thanks
        Michael

  3. Anonymous says:

    Hi Michael,

    can you help me on getting the delivery exception in detail using SOAP Exception set to object type “System.Web.Services.Protocols.SoapException, which you mentioned above.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s