Note: This is an unedited contribution. If this article is inappropriate,
needs attention or copies someone else's work without reference then please
Report This Article
Introduction
Most of us have might have written code to handle exceptions in any
programming language. In BizTalk, exceptions are little bit different. This
article explains how to handle exceptions and notification mechanism in ports,
using some simple scenarios.
Exceptions vs Delivery Notification
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 DeliveryNotificationException is raised
and the exception needs to be handled by the Orchestration.
Scenario 1 : Sending a Sales Report...
Consider a scenario where a sales report needs to be uploaded to a Web
service.
Assumptions
- If the Web service is not responding, it shall be online only after 24 hrs.
- The retry count and interval on the Web Service Port is set to "0".
If the Web service is not responding, an exception is raised, and
is handled by sending the message to an Offline
folder.
 |
| Receive shape - Receives a Sales Report message. |
| |
| |
| Scope shape - A scope defines a context in BizTalk. A scope is used to set a
Transaction Type, in this case, the TransactionType is set to "None". The
scope's Synchronized parameter is set to "true". |
| |
| |
| A Sales Report message is created, so as to tramit it to the web service.
|
|
| Note the properties of the Web Port which are marked in "Red". |
| |
| Delivery Notification - If a message fails to be delivered on a Port, the
"DeliveryFailureException" is generated. Note that
"Delivery Notification" is NOT available for Binding property
"Specify Now". |
| |
| |
There are two kinds of Exceptions handled in this orchestration.
- DeliveryFailure Exception
- General Exception
|
| |
| General Exception - In this case, the message which needed to be sent to the
Web Service, is written out to an Offline Folder. |
| |
| Important Note: DeliveryFailure Exception - This exception is not thrown in
this scenario, since a Web Service Port is request-response port. This is reason
why the exception is handled in the General Exception section.
| |
Event Log messages...
Observe the event log messages...

Scenario 2 : Raising the 'DeliveryFailureException' using a Dummy
folder
In this scenario, we create a "Dummy" folder when messages need to be
transmitted, and since the Dummy folder does not exist, we handle an exception
and send the messages to the Offline folder.
 |
| Receive shape - Receives a Sales Report message. |
| |
| |
| |
| A Sales Report message is created, so as to transmit it to the web service.
|
| |
| Scope shape - A scope defines a context in BizTalk. A scope is used to set a
Transaction Type, in this case, the TransactionType is set to "None". The
scope's Synchronized parameter is set to "true". |
| |
| |
|
| Note the properties of the ReportDummyPort which are marked in "Red".
|
| |
| Delivery Notification - If a message fails to be delivered on a Port, the
"DeliveryFailureException" is generated. Note that "Delivery Notification" is
NOT available for Binding property "Specify Now". |
| |
| |
There are two kinds of Exceptions handled in this orchestration.
- DeliveryFailure Exception
- General Exception
|
| |
| A DeliveryFailure Exception is raised by the Port, since the file path
specified in the Dummy Port does not exist. The exception handler handles the
exception by sending the message into the OfflineFolder. Notice that in this
case the DeliveryFailure Exception has been correctly raised. |
| |
| | |
Event Log messages...
Observe the event log messages...

About the Downloadable Code
- Unzip the Web Service with the folder names into the
C:\inetput\wwwroot directory and setup the web service.
NOTE
- Rename the Persist.asmxto Persist2.asmx so as to
make it unavailable.
- Unzip the BizTalk project zip file with the folder names in the
C:\ drive.
- The folder
KeyAndBindings contains the
Bindings.xml file, which can be imported after the solution is
built and deployed.
- Place the SalesMessage in the
In folder and check the
Offline folder.
Some Takeaways
- Set the
Synchronized property on the Scope shape
to true, in the case you want to handle exceptions.
- Always select the "WebPortType" created when the "Web Reference" is added to
the project, while creating "Web Ports" in the Orchestration.
- Delivery Notification is not available on Early Bound Ports.
DONT's miss the following references...
- Acknowledgments
and Negative Acknowledgments (Part 1)
- BizTalk
2004 Delivery Notification and NACK Sample