Stephen W. Thomas BizTalk Blog

100% Pure BizTalk
posts - 130, comments - 139, trackbacks - 438

My Links

News

Subscribe to my blog via:


Add to Google

Visit my website at:
www.BizTalkGurus.com

Archives

BizTalk 2004 Samples

BizTalk 2006 Samples

BizTalk Videos

BizTalk White Papers

BizTalkBlogs.com

Great BizTalk Blogs

Other Links

BizTalk 2004 Delivery Notification and NACK Sample

Did anyone else read Kevin Smith’s blog on ACK/NACK and run out to try it?  Well, I sure did and found it a little more time consuming then I expected.  I have put together a sample that shows how to catch the SOAP exception and get access to the error message.  I hope that after looking at this sample Kevin’s excellent post on NACK’s will make a little more sense.  It did for me.

 

DOWNLOAD: Get the sample here!

 

Set-up is easy, just unzip the SampleNACK folder and put it on your C: drive.  Then, build and deploy the SampleNACK project. You will need to manually create a Send Port.  I set up a File Send Port going to c:\some_location_that_does_not_exist.  Set retries to 0.  To run it, drop the StartFile.xml message into c:\SampleNACK\In.  Your NACK will show up in c:\SampleNACK\Out.  Do not forget to look inside the expressions shapes inside the Orchestration for comments.  If all else fails, read the ReadMe.txt file. 

 

CRITICAL: Getting at the HTTP error using Delivery Notification will not work for transport type of HTTP or SOAP due to an “issue”.  For more information please see Microsoft KB840008.

 

Key Take Home Points:

- Delivery Notification is not available on Early Bound Ports.

- Must import System.Web.Services to cast the SOAP exception

- Set Send Port retries to 0

- Must use a Synchronized scope

 

Under the covers:

Ok, so you ask what is BizTalk doing inside the little Delivery Notification property? Keep in mind this is my interpretation. 

 

When a message is sent through a send port with Delivery Notification set to transmitted, a correlation set is initialized.  A correlation token is assigned to the outbound message.  A subscription is started based on this correlation token.  This token is stored in the context property of the ACK/NACK and promoted.  When the ACK/NACK is returned, it is routed back to the calling Orchestration.  You get all this just by setting a little property to “Transmitted”!  Cool!

 

Take Away: Delivery Notification is an easy way to catch exceptions as long as you understand how to get at the error message.

Print | posted on Monday, August 02, 2004 10:23 PM |


Feedback

# re: BizTalk 2004 Delivery Notification and NACK Sample

Great Stephen..I have been looking around for a sample on how to deal with the nack and now understand what I was doing wrong. Thanks! 8/5/2004 12:25 AM | jeremy

# Ack and Nack in biztalk

Ping Back??:???? 8/9/2004 1:00 AM | Evan

# re: BizTalk 2004 Delivery Notification and NACK Sample

SoapException just be accepted in Atomic scope .If I use long-running scope,what could you do ? 8/31/2004 7:14 AM | Nguyen

# re: BizTalk 2004 Delivery Notification and NACK Sample

I do not think I would work in a long running transaction scope. The scope share has to be atomic since the SOAP exception is nonserializable. 9/1/2004 7:58 PM | Stephen W. Thomas

# Handling errors in Orchestrations from invoked WebServices

When you are invoking WebServices from your BizTalk Server 2004 orchestrations, you might need to ensure that two things happen... 3/29/2005 10:01 PM | Commonality

# re: BizTalk 2004 Delivery Notification and NACK Sample

I've tried the sample. It works fine. I also already made a same sample myself, that does the same.

The thing is, I want to use exception handling to prevend messages to get suspended. Is there a way to achieve this?

With kind regards,
Jorryt de Vries
jorrytdevries@hotmail.com
Amsterdam 5/20/2005 5:52 AM | Jorryt de Vries

# re: BizTalk 2004 Delivery Notification and NACK Sample

Hello.

I do not think this is possible to prevent the message from being suspended. Since when you get the NAck message the original message will have already suspended.

You could extract out or reprocess the suspended messages inside the Orchestration. Although, this would probably suspend as well since the problem that caused the message to suspend in the first place was not fixed.

Hope this helps.

Stephen W. Thomas
5/30/2005 11:43 PM | Stephen W. Thomas

# re: BizTalk 2004 Delivery Notification and NACK Sample

Hi, Ive encoutered an interesting issue when using the Deleivery Notification features of the orch send port. If I subscribe an additional send port to the message that is being sent by the orchestration (e.g a test send port subscribed to the MessageType) this test port will result in the orch picking up an Ack from the test port - producing some unexpected results. My understanding was that ports direct bound to the message box should not result in an Ack finding its way back to the orchestration - it would seem that this is not the case and if you add additional subscriptions to your messages (that are marked with AckRequired) these additional ports will result in an Ack/Nack finding its way back to your orchestration, and depending on which one gets in first you will have some interesting things happening in y0our workflow. Can anyone confirm this is the case and even better - suggest a way that these direct bound ports can be stopped from issuing a Nack message back to the orhestration. 10/3/2005 6:37 PM | Adam Asher

# re: BizTalk 2004 Delivery Notification and NACK Sample

Hello.

I’m a little confused about what you are trying to do.

You can not use Delivery Notification with Direct Bound send port. With that said, I have never tried to get it to work or not work. I have tried setting the AckRequired property and always seemed to have it overridden by the send port no matter what I set it to inside the context.

If you have multiple Send Ports through a Send Port group you would get back an Ack or Nack from whoever returns it first.

Maybe restructuring your Orchestration would prevent your strange behavior. If you want to send it to me I’d be happy to take a look at it.

Stephen W. Thomas
10/3/2005 7:44 PM | Stephen W. Thomas

# re: BizTalk 2004 Delivery Notification and NACK Sample

I receive a message, construct three different messages and send all the three in a sequence to the same send port.
For sending to the send port i have a call orchestration. It receives the message as parameter and then sends it over to send port.

I need all the three messages to be delivered in the same order. But for some reason they are all comming out randomly.

Any Idea? 4/6/2006 2:00 PM | Padmaja

# re: BizTalk 2004 Delivery Notification and NACK Sample

You would need to set OrderedDelivery=true on your send port.
4/16/2006 8:13 PM | Naveen

# re: BizTalk 2004 Delivery Notification and NACK Sample

Excelent, Stephen.

I'd like to know how I can cast the SOAP message to get rid of the SOAP envelope.

Thanks,

Juan 4/26/2006 8:00 AM | Juan Piacquadio

# re: BizTalk 2004 Delivery Notification and NACK Sample

Did you take a look at the sample? If I remember correctly, I cast in the SOAP message. Then, you should be able to do anything you want with the data since it is XML (i.e. map is or extract anything you want).

Stephen W. Thomas
4/26/2006 8:10 AM | Stephen W. Thomas

# re: BizTalk 2004 Delivery Notification and NACK Sample

Thanks Stephen.
I have a much less elaborated orchestration to handle the errors. 4/26/2006 9:04 AM | Juan Piacquadio

# re: BizTalk 2004 Delivery Notification and NACK Sample

Stephen,

Please see below the error that I am getting.

-----------------------------------------------------
Event Type: Error
Event Source: XLANG/s
Event Category: None
Event ID: 10034
Date: 4/26/2006
Time: 10:32:57 AM
User: N/A
Computer: USSYXX14
Description:
Uncaught exception (see the 'inner exception' below) has suspended an instance of service 'SampleNACK.CatchNACK(cf6e2475-6f0f-41b3-08b7-5b8ea0ee6ed0)'.
The service instance will remain suspended until administratively resumed or terminated.
If resumed the instance will continue from its last persisted state and may re-throw the same unexpected exception.
InstanceId: 10297de4-4d14-4545-b09a-b96997d1fd50
Shape name: Cast
ShapeId: 44a06129-0856-44d7-8a0a-b7e69d4c0fb6
Exception thrown from: segment 4, progress 4
Inner exception: Unable to cast object of type 'System.Exception' to type 'System.Web.Services.Protocols.SoapException'.

Exception type: InvalidCastException
Source: SampleNACK
Target Site: Microsoft.XLANGs.Core.StopConditions segment4(Microsoft.XLANGs.Core.StopConditions)
The following is a stack trace that identifies the location where the exception occured

at SampleNACK.CatchNACK.segment4(StopConditions stopOn)
at Microsoft.XLANGs.Core.SegmentScheduler.RunASegment(Segment s, StopConditions stopCond, Exception& exp)



For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.
------------------------------------------------

Thanks,

Juan 4/26/2006 9:48 AM | Juan Piacquadio

# re: BizTalk 2004 Delivery Notification and NACK Sample

Stephen,

I am working on BizTalk 2006, might that be the problem?

Thanks,

Juan 4/26/2006 10:18 AM | Juan Piacquadio

# re: BizTalk 2004 Delivery Notification and NACK Sample

No, it should work in 2006.

Not sure what the problem is – but I’d guess it’s trying to cast a NACK that doesn’t exist. Do you have Delivery Notification enabled on the send port?

Check the solution files in the Solution directory. They might help.

Stephen W. Thomas
4/26/2006 10:43 AM | Stephen W. Thomas

# re: BizTalk 2004 Delivery Notification and NACK Sample

In the PortToKnowWhere "Delivery Notification" is set to "Transmitted".

The only different thing that I did is changing the folder where the solution is placed. But I changed the IN and OUT folders as well.
Any other ideas or suggestions? 4/26/2006 11:19 AM | Juan Piacquadio

# re: BizTalk 2004 Delivery Notification and NACK Sample

I got what was wrong.
I pointed the port to a folder that "does" exist and then the error was not generated.

Thanks,

Juan 4/26/2006 11:23 AM | Juan Piacquadio

# re: BizTalk 2004 Delivery Notification and NACK Sample

Stephen,

How can I capture errors related to the pipelines or the maps?
I tried using another Exception Object Types in the CatchDeliveryExc but it did not work. 4/26/2006 3:09 PM | Juan Piacquadio

# re: BizTalk 2004 Delivery Notification and NACK Sample

Nope, not an easy way to do this in 2004. 2006 you can - but not really with Delivery Notification (unless they changed it - guess I haven't tried yet).

You’d have to use MOM or something else to watch for suspended messages using WMI.

Stephen W. Thomas
4/27/2006 9:16 AM | Stephen W. Thomas

# re: BizTalk 2004 Delivery Notification and NACK Sample

Hi Stephen,

this is really great stuff, thanks a lot.

A thought though: is it really necessary to set retry count to 0 on the send port? I tried to have a few retries and it seems to work fine. The only thing that happens is that the orchestration waits for ACK/NACK. Or am I missing something?

I'm using BT 2004.

Pelle 7/31/2006 8:16 AM | Pelle

# re: BizTalk 2004 Delivery Notification and NACK Sample

No, there is no problem with setting the retry count. That just means you have to wait for the retries before you get the NACK.

Stephen W. Thomas 7/31/2006 8:37 AM | Stephen W. Thomas

# re: BizTalk 2004 Delivery Notification and NACK Sample

Ok, great. Thanks. 7/31/2006 9:06 AM | Pelle

# re: BizTalk 2004 Delivery Notification and NACK Sample

Hello again,

what is needed to be done to get an ACK/NACK from send adapter if you're not using orchestration? I have a custom pipeline component where I could set some context properties for example. I want the adapter to publish an ACK in the messagebox (another orchestration will wait for this ACK).

Which would these properties be? I tried the BTS.AckRequired = true but alone that didn't work. 8/8/2006 5:05 AM | Pelle

# re: BizTalk 2004 Delivery Notification and NACK Sample

I’ve never tried to get that to work in 2004.

In 2006, it’s just subscribing to the suspended message.

Stephen W. Thomas
8/8/2006 9:24 AM | Stephen W. Thomas

# re: BizTalk 2004 Delivery Notification and NACK Sample

How would I do this with a 2-way Request-Response port? I need to check the incoming message and if its an invalid message, I need to send back the reponse (over an Http adapter). 9/28/2006 1:05 PM | Pras Biswas

# re: BizTalk 2004 Delivery Notification and NACK Sample

You don’t need to set this up with a Request-Response port. It will send the ACK/NACK back for you automatically. So just by setting up a Request-Response port you get this functionality.

Stephen W. Thomas
www.BizTalkGurus.com
10/4/2006 6:30 AM | Stephen W. Thomas

# re: BizTalk 2004 Delivery Notification and NACK Sample


can you please tell me how to import the System.Web.Services dll. I didn't find in my variable type selector.
12/29/2006 9:27 PM | devaraj

# re: BizTalk 2004 Delivery Notification and NACK Sample

You need to make sure you add the corrected reference to your project first and if using VS 2005 you may need to refresh your project to see all the references.

Check out my sample if you have questions.

Stephen W. Thomas 12/30/2006 3:49 AM | Stephen W. Thomas

# re: BizTalk 2004 Delivery Notification and NACK Sample

Can i in any way Get Delivery notification Exception in a Send Pipeline?
We do some operation in a Send Pipeline Component which needs to be reverted back if the Message delivery has failed..
Please help me.... 4/1/2008 6:21 AM | vignesh

# re: BizTalk 2004 Delivery Notification and NACK Sample

You can't get a delivery notification in a pipelines. But if you use an Orch to call that send port you should be able to.

Hope this helps.

Stephen W. Thomas 4/10/2008 10:32 AM | Stephen W. Thomas

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 7 and 2 and type the answer here:

Powered by: