Delivery Notification with Direct Send Port
It's been a while I'm trying to understand how to perform a Delivery Notification on a BizTalk Direct Logical Send Port. All the samples and the posts around the issue never mentioned sending the message directly into the MsgBox. They all talked about the guidance of performing the ACK/NACK on a Specify Later, Specify Now or Dynamic port configuration - not Direct.
Well here is how I did it on a Direct style:
1. Assuming the message I'm trying to send (and check for delivery) is called msgDeliver, On a Message Assignment Shape before the Direct Send Shape, write the following:
//Restore the original message using XmlDocument
msgDeliver = xDoc;
//Set the Acknowlegment Flag to true
msgDeliver(BTS.AckRequired) = true;
//Generate a correlation token
msgDeliver(BTS.CorrelationToken) = System.Convert.ToString(System.Guid.NewGuid());
//Set a routing value like the SPTransport
msgDeliver(BTS.SPTransportID)="{4504D95B-5E81-42CF-912D-17A7362E2024}";
2. Add a Send Shape to send the msgDeliver message and link it to a logical Direct Send Port.
3. Create three separate Correlation Sets for BTS.AckRequired, BTS.CorrelationToken and BTS.SPTransportID.
4. Configure the Send Shape to Init the three above correlation sets.
5. Create a new message and call it msgAckNack of type - System.Xml.XmlDocument.
6. Under the send shape add two Direct Receive Shapes, config them to follow the correlation for BTS.CorrelationToken (the first is a dummy subscription for the message sent and the second is for the SOAP NACK message, or the kind of empty ACK message).
7. Configure the two receive shapes to get the msgAckNack message, and link the two receive shapes to a logical direct receive port.
8. Now you can analyze the msgAckNack and see if the message was deivered safely (no need of a Scope shape to get the DeliveryNotification exception because there the NACK is not interprated here as an exception).
9. On a succesful delivery the msgAckNack will contain something like:
<String/>
and on a failing delivery it will contain a SOAP message like that:
<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" SOAP:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP:Body><SOAP:Fault><faultcode>Microsoft BizTalk Server Negative Acknowledgment </faultcode><faultstring>An error occurred while processing the message, refer to the details section for more information </faultstring><faultactor>C:\TestSendListen\Send1\%MessageID%.xml</faultactor><detail><ns0:NACK Type="NACK" xmlns:ns0="http://schema.microsoft.com/BizTalk/2003/NACKMessage.xsd"><NAckID>{0BC59C8E-45A2-4292-B1FA-05D1ABA00D27}</NAckID><ErrorCode>0xc0c01c10</ErrorCode><ErrorCategory>0</ErrorCategory><ErrorDescription>The FILE send adapter cannot open file C:\TestSendListen\Send1\{846067E1-5C29-4EAE-9308-401B7F913B4F}.xml for writing.
Details: The system cannot find the path specified.
</ErrorDescription></ns0:NACK></detail></SOAP:Fault></SOAP:Body></SOAP:Envelope>