How to Send Fault Message from BizTalk Orchestration

In my previous blog I tried to explain how to 'receive' a Fault message in BizTalk orchestration. This one will talk about how to 'send' a fault message, when BizTalk is exposed as service.
In this sample I will perform checks using decision shape, on first branch I will send the response message and in the other I will send the constructed Fault message.

 

By default when you create a 2 way port in the orchestration you will only see, a request and a response message. Right click on the port operation and Add New Fault Message.

Also make sure you enable the 'Include Exception detail in Faults' for the Fault details to be transmitted across to the Client. You can find this option under Messages section of the receive location configuration.

After performing all these changes, my orchestration which is now exposed as a service. When invoked from the client, I receive the Response and Faults as expected.

If anything goes wrong in orchestration, handle it and send across it also as a fault like below. In this sample, orchestration does all its processing and sends the response and for any exceptions caught, it constructs Fault message and send the same.

When I do this, I get a compile time error must receive before sending a fault message on an implemented port”. After doing some research, comparing what is different from the first scenario I see that when Fault message is send from Biztalk orchestration I need to send the Fault and Response in different branches of the decision shape. The compile time check makes sure that there is only either a response or a Fault which is sent under any circumstance and not the both.

So the next question is, how to implement the above scenario: catch an exception and send a fault, with a condition that response and Fault need to be in different branches.
You can do it in multiple ways; use a call orchestration which will perform all your processing, based on whether exception or response message sent from the child Orchestration perform a decision on parent Orchestration and send Response/Fault to the client.

Since, my service is a simple one I used a flag that will get updated in the catch block and use the flag in the decision shape to send either the request or the response as shown below.

Hope this helps!

Happy BizTalking!!

Written by
Shashidharan Krishnan

Reviewed by
Jainath Ramanathan

Microsoft GTSC, India