Will a Send Port with no filter create any subscription?

If you just create and configure a Send Port (with any adapter and pipeline) and no Filter specified, will it create any subscription once you have started/enlisted the Send Port?

Many times, I have seen people getting confused and say, it will not create any subscription till we specify the Filters on the Send Port. But the answer is, yes, it will create a subscription even if it doesn’t have any filters.

Lets check that out.

1. Create a Send Port in any BizTalk Application and configure it with any adapter and pipeline of your choice.

SendPortSubscription1

2. Make sure we have not specified any Filters on this Send Port.SendPortSubscription2

3. Go ahead and start this Send Port.

4. Now, do a query on Subscriptions as show below and specify the name of your send port as ServiceName.

SendPortSubscription3

5. You should find one Activation Subscription for your Send Port created above.

6. And if you open it, you will find the below susbscriptionSendPortSubscription4It means, that BizTalk internally has create a subscription for the Send Port although we have not explicitly defined any filters for it.

Now, you may be wondering where it will be used. It is used when you bind a Send Port with an orchestration logic port. Once you bind the physical Send Port with an orchestration logical port, Orchestration then comes to know about this SPTransportID of the Send Port. When Orchestration needs to send a message to this Send Port, it just promotes this SPTransportID into the context of the message while publishing the message to the MessageBox and the message is then routed to the same Send Port.

I hope it helps.

Duplicates and Zombies with HTTP Adapter while using Delivery Notification

I have seen an interesting issue while using HTTP Adapter and thought about sharing with you all. Many times, I saw that we posted duplicate messages to HTTP URL from our HTTP Send Port or sometimes orchestration which is sending message to this HTTP Send Port, got suspended with error “The instance completed without consuming all of its messages. The instance and its unconsumed messages have been suspended.” and which typically refers to a zombie message in BizTalk world.

On analysis, we found it to be an issue with one-way HTTP Adapter while an orchestration is sending a message to it with Delivery Notification enabled. This happens when we have another subscriber (a Send Port) subscribing to the same message going to this HTTP Send Port.

Let me show you how we can easily reproduce this issue.

1. For the repro, we will use the HelloWorld SDK sample solution. First, lets open the HelloWorld.sln Solution which it typically located under \SDK\Samples\Orchestrations\HelloWorld folder. On my box, the directory is C:\Program Files (x86)\Microsoft BizTalk Server 2013\SDK\Samples\Orchestrations\HelloWorld.

2. Open the HelloOrchestration.odx and go to the SendInvoicePort Port properties and change the Delivery Notification to Transmitted.

HTTPSendPort1

3. Build the solution and deploy it to any BizTalk application. You may need to sign the assembly with a strong name key file.

4. Create a one way Send Port with HTTP Adapter and point it to any HTTP URL where messages can be posted. In my case, I am using another HTTP receive location for receiving messages over HTTP.

HTTPSendPort2

5. Create a Receive Port with a receive location and configure it with File Adapter and XMLReceive pipeline.

6. Bind the HelloWorld orchestration with the Receive Port and HTTP Send Port created in earlier steps.

HTTPSendPort3

7. Now the HelloWorld sample is good to test after you have recycled the host instances and started all the artifacts used. If you drop the SamplePOInput.xml (located under the HelloWorld folder) in the file location configured earlier, the orchestration will post the message to HTTP URL through HTTP Send Port. If everything is set up correctly, you will see an Invoice xml message posted to the HTTP URL.

8. Till here, everything is working as expected. But before we repro the issue, let me show you how Delivery Notification is working here.

For this, we will stop the HTTP Send Port and drop one more input file.

HTTPSendPort4

Now query for All In-Progress Service Instances and you will see that the HTTP Send Port is in suspended (resumable) state and Orchestration is in Dehydrated stage. Send Port is suspended as we have kept it stopped and orchestration is dehydrated as it waiting for the the ACK from the Send Port since we have enabled the Delivery Notification.HTTPSendPort5

If you query for the subscriptions, you will find that there is an instance subscription for our orchestration instance which is in dehydrated state, and it has got a subscription on Correlation Token as shown below.

HTTPSendPort6

Now, if you open the suspended Send Port instance, and go to the context of the message, you will see Correlation Token in the context property and the value matches to the value found above in the subscription of the orchestration instance. Also note that there is another property AckRequired with value True. This tells the Adapter to publish an ACK back, with the same correlation token, after it is done processing so that orchestration can come to know about it. That is how the Delivery Notification works.

HTTPSendPort7

Now this explained, let’s go back to repro our issue.

9. We will create another one way Send Port with File Adapter and point it to any file location. Add the below filter on this Send Port so that it subscribes to the message going to the HTTP Send Port directly from the MessageBox.

BTS.MessageType == http://HelloWorld.InvoiceSchema#Invoice

HTTPSendPort8

This will also mean that both the HTTP and File Send Port will receive the same message. HTTP Port is directly bound to the Orchestration and File Port will subscribe to the same message directly from the MessageBox.

10. Keep both the Send Port’s (i.e. both File and HTTP) in the stopped state and drop the input file. Now you will see that both the Send Ports are in stopped
HTTPSendPort9

Now, point to note is that both have received the same copy of message and if you open the context for both the suspended messages, they will have the same Correlation Token in the Context and will also have the AckRequired as True. So both the Send Ports are capable to sending the Ack back to the orchestration instance after they got processed and orchestration cannot differentiate from where the Ack is coming as it is only cares about the right value of Correlation Token.

11. Right click the suspended File Send Port message and resume it. You will find that both File Send Port message and orchestration have completed. But HTTP Send Port message is still suspended as we have not resumed it.

12. Now resume the suspended HTTP Send Port message, and after a while you will observe that Send Port is stuck in active state and there is also a Routing Failure Report.  HTTPSendPort10

If you check at the receive HTTP URL, you will observe that the URL received the message successfully, but the message at HTTP Send Port is stuck in Active state for ever.

So what is happening is that after the HTTP Send Port has finished processing (i.e. posting to HTTP URL), it is trying to publish the ACK to the MessageBox but since now the orchestration has already completed, it is not able to find any subscriber for it and failing with the Routing Failure Report. But somehow I believe that adapter is not handling it properly and getting stuck with active state.

13. So now if I go and just recycle the host instance, you will observe that a new Routing Failure Message is suspended and Send Port is still in Active state. And if you check at the receiving HTTP URL, another copy of message would have been received. So that means, every time we recycle the host instance, a duplicate message will be sent to the HTTP URL.

HTTPSendPort11

Note that the above we tried to reproduce a scenario, where the file adapter got processed first and sent the ACK back to the Orchestration first while HTTP Adapter took some time to get processed.

Ideally, the HTTP Send Port should not be stuck in Active state and it should have been suspended saying no subscribers found for the ACK. If we use a File adapter instead of HTTP Adapter and try to repro it, we will see that it will get suspended with error “The published message could not be routed because no subscribers were found. “.

This scenario can easily occur in Prod, if someone create a Send Port (maybe for archival or something else) with filter on MessageType for the message going to HTTP Send Port.

We can also easily reproduce zombie with the same repro. Keep both the Send Ports in suspended state and drop the input file again. Now resume both the suspended Send Ports together and if you got the right timing (i.e. both adapters were able to publish their ACK before the orchestration completes), you will see that the orchestration got suspended with error “The instance completed without consuming all of its messages. The instance and its unconsumed messages have been suspended.”. It means that orchestration received the Ack which got published first and the orchestration started processing further. And the second Ack, which got published after the first but before the orchestration completes, got treated as a zombie message.

With this, we have reproduced both the issues. The first issue, i.e. HTTP Send Port stuck in active and sending duplicates at every recycle, is more like an issue with HTTP Adapter as I am not able to reproduce it with any adapter. But the second issue, i.e. about orchestration getting suspended is a more legitimate issue and can occur with any adapter. To resolve the second issue, we can suppress the AckRequired by using a pipeline at the second Send Port (in our repro it will be File Send Port). Below is a snippet of the code, we can use at the pipeline at the Send Port which will make the AckRequired property to false, so that the adapter will not publish the Ack to the MessageBox.

if (inmsg.Context.Read("AckRequired", "http://schemas.microsoft.com/BizTalk/2003/system-properties") != null)
            {
                if (inmsg.Context.Read("AckRequired", "http://schemas.microsoft.com/BizTalk/2003/system-properties").ToString() == "True")
                {
                    inmsg.Context.Write("AckRequired", "http://schemas.microsoft.com/BizTalk/2003/system-properties", "False");
                }
            }

Note that I have reproduced this issue on BizTalk 2009 and as well as  BizTalk Server 2013 R2.

That’s all for now. Let me know what you think about this post.

Simulating LOB Application using WCF LoopBack Adapter Binding in BizTalk

I am a big fan of WCF LoopBack Adapter Binding in BizTalk and would like to share a trick which I often use to simulate LOB Application while I am developing a new orchestration.

Many times when we are developing an orchestration which need to interacts with an LOB Application (using solicit response Send Ports such as SQL, SAP, etc), we are often stuck to complete the unit testing since there can be limitations to integrate with LOB App on our dev boxes or may be LOB App is not ready to start integration testing. Due to this we may sometimes not able to complete the dev of orchestration or even if have done, we might not be able to properly unit test it.

In these situations, I use WCF LoopBack Adapter Binding using which I can simulate any response expected out of solicit response Send Port of the LOB App.

I am not going into details on how to develop the WCF LooBack Adapter binding and how to install and configure it for your BizTalk box. For more details on this binding, you can refer to this excellent post http://synthesisconsulting.net/blog/2012/5/17/biztalk-wcf-loopback-binding.html

For example, lets say that I need to call a SQL Stored Procedure from the Orchestration and will be using a WCF-SQL Adapter on a solicit response Send Port. I do have the request and response schema’s and have completed the orchestration development using that but wanted to test my orchestration for different scenarios once it receive the response back from the SQL.

For this to simulate, I create a new Send Port using LoopBack Adapter Binding as shown below and will be binding this port to the Orchestration for testing.

1. Create the Send Port using LoopBack Adapter binding. Make sure to select the XMLReceive pipeline for the Receive Pipeline.LoopBackSendPortConfig1

2. Set the URI and Action Header as required for the LoopBack Adapter binding.

LoopBackSendPortConfig2

3. Keep the binding Configuration to Default.

LoopBackSendPortConfig3

4. This is the most important step where we define what response message will be sent back by this Loopback Adapter, Come to Messages Tab and set the Outbound WCF Message Body as Template. Now specify the response message which is expected from the LOB App (here SQL) and which matches the response schema as well.

For my example, lets say the response expected looks like below.

<ns0:SQLResponse xmlns:ns0=”mycompany”>
<ns0:Response>
<ns0:Status>0</ns0:Status>
<ns0:Data>
<ns0:Property>test</ns0:Property>
</ns0:Data>
<bts-msg-body xmlns=”http://www.microsoft.com/schemas/bts2007&#8243; encoding=”xml”/>
</ns0:Response>
</ns0:SQLResponse>

Make sure that you include the bts-msg-body (which represents the request message) somewhere inside it as shown above. This mostly will be ignored by the XMLReceive pipeline at the Send Port and the Orchestration as we are not doing any validation on the response message.

LoopBackSendPortConfig4

Now you are good to test the orchestration with this Send Port simulating the SQL LOB App. We can keep changing the response date for simulating different scenarios and test the orchestration flow. For above example, I can change the Status to 1, 2, etc as per my scenario and test the behavior of orchestration.

At times, this little trick comes very handy and as a developer, it gives me confidence while developing BizTalk solutions in a early stage.

SendFailedException while using RoleLinks

Few days back, we were running into an issue where we were receiving the below exception while sending a message from an Orchestration using RoleLinks.

Microsoft.XLANGs.Core.SendFailedException: Failed while attempting to send message ‘msgXXXXXXXX‘. —> System.Runtime.InteropServices.COMException (0xC0C01672): Exception from HRESULT: 0xC0C01672
at Microsoft.BizTalk.Interop.IBTPEPInfoLookup.PostToSendPort(Guid& sendPortID, IBTMessageBatch batch, IBTMessage msg, String operationName, String url, IBTMMessageList& dlMsgList)
at Microsoft.BizTalk.XLANGs.BTXEngine.BTXXlangStore.WriteMessageState(IBTPEPInfoLookup pepLookup, Guid portId, XLANGMessage msg, Segment seg, String opname, String url, IList promoteProps, Boolean track, IList toPromote)
— End of inner exception stack trace —
at Microsoft.BizTalk.XLANGs.BTXEngine.BTXXlangStore.WriteMessageState(IBTPEPInfoLookup pepLookup, Guid portId, XLANGMessage msg, Segment seg, String opname, String url, IList promoteProps, Boolean track, IList toPromote)
at Microsoft.BizTalk.XLANGs.BTXEngine.BTXLogicalPortBinding.SendMessage(XLANGMessage msg, XlangStore store, Segment seg, OperationInfo op, IList additionalProps, IList toPromote, Boolean ignoreRoutingFailure)
at Microsoft.BizTalk.XLANGs.BTXEngine.BTXServiceInterfacePortBinding.SendMessage(XLANGMessage msg, XlangStore store, Segment seg, OperationInfo op, IList additionalProps, IList toPromote, Boolean ignoreRoutingFailure)
at Microsoft.BizTalk.XLANGs.BTXEngine.BTXPortBase.SendMessage(Int32 iOperation, XLANGMessage msg, Correlation[] initCorrelations, Correlation[] followCorrelations, Context cxt, Segment seg, ActivityFlags flags)

After long troubleshooting, we found that the issue is because the RoleLink was not getting properly initialized in the Orchestration. We were not setting the value of strDunsNumber which was used to initialize the RoleLink as below.

RoleLink_XXXXXXXXXXX(Microsoft.XLANGs.BaseTypes.DestinationParty) = new Microsoft.XLANGs.BaseTypes.Party(strDunsNumber, "1");

Somehow, I feel that the exception raised was misleading and doesn’t point to the actual issue.

BizTalk Server Resources on the TechNet Wiki

In case you missed it, there is a whole bunch of  BizTalk Server Resources available on the TechNet Wiki site. Below is a link to it

http://social.technet.microsoft.com/wiki/contents/articles/2240.biztalk-server-resources-on-the-technet-wiki.aspx

It contains links to all the cool BizTalk Wiki Articles. Apart from Wiki articles, it also contains links to Product documentation, Developer Center, Labs, etc. So, definitely a very handy article. Smile

Get the party name from Qualifier Name Value Pair

Sometime back, we ran into an scenario where we need to get the Party name from the Qualifier Value pair specified at the Party. The Party name was needed as we need to send the EDI XML message to a LoopBack Send Port with EDISend Pipeline (note that EDI pipelines cannot be call from within orchestration or is not supported, so we send the message from Orchestration to a Send Port with LoopBack Adapter and execute the EDI pipeline) so that it can convert the EDI XML to EDI raw with appropriate Party EDI Settings and return EDI raw message.

We need to identify the Party name from the Qualifier Value pair specified at the Party, as the Qualifier Value pair was the only information available to the Orchestration.

We used the following expression to get the Party name as string.

 

party = new Microsoft.BizTalk.Edi.PartnerAgreementManager.Partner("1","12345");

 

And then we added the property EDI.DestinationPartyName to the context of the message with the party name returned above. The message was sent to the LoopBack Send Port and EDISend Pipeline applied the respective Party EDI settings.

 

messageEDIXML(EDI.DestinationPartyName) = party; 

 

image

This was for BizTalk 2009. I am not sure if the same expression applies to BizTalk 2010 or BizTalk 2013 as the Partner Agreement Management is different in these recent versions of BizTalk.