Freigeben über


How to handle Fault Message in BizTalk server

In this article I will explain how to use Fault Message in BizTalk. When a web service is called, the service might encounter exception (System exception or User defined exception).
The service then serializes the exception and sends across the client as a Fault Message.

My client here is BizTalk and since it is a solicit response port; this kind of scenario is handled by orchestration.

There is an option in send port which will specify whether to allow the fault to travel to orchestration or not.

If we do not enable this option, then the fault message received by the send port is not allowed to go to the orchestration as a Message instead it is treated as any other transmission error in the send port
and the orchestration gets a XlangSoapException object back. If there is an exception handling block for this type or its base type, the exception is handled in orchestration accordingly.

If we enable the “Propagate fault message” option, then the send port is not suspended instead sends the serialized Fault message to the Orchestration. These are the steps on how to handle that fault message in Orchestration.
I am using the standard fault message schema in my example below. You also can have a custom fault message in the service, in which case the custom fault message schema will also be created along, when we create the proxy of the service in
the BizTalk project.

First, add a new Fault Message to the operation that is involved either by right clicking on the operation from the port surface or from the Orchestration View as shown below.

 

 

Here, I am creating a Fault Message with the default name Fault_1

 

 

Select the Message type as BTS.soap_envelope_1_1.Fault(You can also select any other custom fault message that the service will send). If your service confines to Soap1.2 then select fault1_2 Messagetype.

 

Now, add an exception handling block to the scope enclosing the send shape, in the drop down of the exception object type select the fault message that we created and I have named the exception object name as SoapFault, as shown below.

 

In the exception handling block, you can handle the exception using the exception object SoapFault(which is actually a biztalk message not a .Net object). I my example, I have extracted the fault string and logged it.

strfaultmessage = xpath(SoapFault, "string(/*[local-name()='Fault' and namespace-uri()='https://schemas.xmlsoap.org/soap/envelope/']/*[local-name()='faultstring' and namespace-uri()=''])");

In this way, you can handle a fault message. You can add multiple fault message provided the fault type is different to an operation and handle the fault in the same way. If the biztalk port receive a fault type which is not handled then it is handled by the default fault type.

Happy Biztalking!!

Written by
Shashidharan Krishnan

Reviewed by
Shailesh Agre

Microsoft India GTSC

Comments

  • Anonymous
    January 04, 2015
    Can we have the Sample Code for this example.Thanks

  • Anonymous
    January 26, 2016
    Nice....it was helpful while i was struggling to catch the same exception

  • Anonymous
    January 28, 2016
    Port1.Helloworld.Fault_1 is not displaying to select in Exception Object Type.....What could be the reason..?Please suggest

  • Anonymous
    July 24, 2017
    Thanks for the post.