How to integrate BizTalk Server 2010 / 2013 with Service Bus for Windows Server

This solution shows how to integrate a BizTalk Server 2010/2013 application with Service Bus for Windows Server using the WCF-Custom adapter to exchange messages with external systems in a reliable, flexible, and scalable manner.

C# (5.3 MB)
4.7 Star
1,704 times
Add to favorites
E-mail Twitter Digg Facebook
Sign in to ask a question

    1 Posts | Last post October 12, 2017
  • SharedAccessSecretTokenProvider with BizTalk
    2 Posts | Last post December 05, 2016
    • Hi Paolo,
      Many thanks for this very useful sample. I am using it as a starting point for building a BizTalk integration that supports acquiring SAS secrets at runtime from Key Vault. I have reproduced your TokenProviderEndpointBehavior and simply substituted a SharedAccessSecretTokenProvider for the TokenProvider types used in your example. I have debugged into this code and can see that the TransportClientEndpointBehavior is created with a TokenProvider that is of the right type and with the correct parameters, and it is added to bindingParameters as I'd expect. However I am finding that the outgoing requests to Azure are missing an Authorization header, and Azure responds with "0102: Missing authorization token"
      I have posted a StackOverflow question:
      I have looked through your code thoroughly and am quite sure there isn't anything else there required for this to work that I have missed. Would you have any idea why this wouldn't work?
    • Hi 
      I did the samples years ago, so I don't remember the details. :) It's quite some time I don't use WCF anymore. You are probably missing some authorization element in the header of the SOAP envelope, or maybe is not properly signed. Sorry :(
  • Biztalk 2013 & servicebus api
    2 Posts | Last post September 19, 2014
    • Paolo,
      Is it possible to read a message from the queue with BizTalk 2013 IF the messsage was written to the queue via the Microsoft.ServiceBus.dll API?
    • Hi Peter
      my soluton uses the WCF-Custom adapter along with the NetMessagingBinding to send and receive messages. The applications sending messages to BizTalk need to use WCF and the NetMessagingBinding. You may use the Service Bus .NET API in the Microsoft.ServiceBus.dll, but you need to do some magic before sending the message as a BrokeredMessage to make it digestible to a WCF-Custom + NetMessagingBinding receive location. You can find that snippet in the code of my Service Bus Explorer tool. Note: BizTalk Server 2013 R2 introduced a new SB-Messaging adapter that supports Service Bus 1.1, that is, the on-premises version of the Service Bus.
  • biztalkSecurity endpoint behavior for SAS
    3 Posts | Last post June 10, 2014
    • Hi paolo,
      Is it possible to use Share Access Signature authorization with the biztalkSecurity endpoint behavior? 
      I have a Service Bus for WS 1.1 with AuthorizationRules that are assigned and instead of using the user/mdp/domain parameters, I would prefer to use the SAS key and SAS secret. Is it possible with the current version (I don't think so) and is it easy to update if it is not supported yet?
    • Hi David
      I did the component way before SAS was made available, so I never tested the component with SAS. ;) Unfortunately, in the meantime I changed focus, so I doubt I'll have time to make this test. :( Sorry about that!
    • Hi Paolo,
      No pb about that. I hope that BizTalk 2013 R2 will be release soon and according the what's new, the updated SBMessaging adapter will support SAS, so no more WCF behaviours needed ! 
  • Biztalk 2013 and ServiceBus 1.1
    4 Posts | Last post May 30, 2014
    • Thank's for your sample.
      But I have a problem to receive message.
      When I sent a message with Service Bus Explorer, I trying the 3 body type for a xml mesage but I have this warning on the event log :
      When I use Body Type WCF :
      The WCF service host at address "sb://win2012/ServiceBusDefaultNamespace/Test" has received a Message addressed to "" which cannot be processed. If the HTTP transport was used, ensure that the HTTP Verb is correct.
      When I use Body Type string :
      The adapter "WCF-Custom" raised an error message. Details "System.ServiceModel.CommunicationException: Unrecognized message version.
         at System.ServiceModel.Channels.ReceivedMessage.ReadStartEnvelope(XmlDictionaryReader reader) ...
      When I use Body Type stream :
      The adapter "WCF-Custom" raised an error message. Details "System.Xml.XmlException: The input source is not correctly formatted.
         at System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader reader, String res, String arg1, String arg2, String arg3) ...
      Please help !
    • Hi mate
      Unfortunately I don't have time to investigate the problem. I suggest to proceed as follows:
       - Use the client application contained in the solution to send message to the WCF-Custom receive location(s) of the BizTalk application.
       - Make sure to enable WCF message tracking:
            <messageLogging logEntireMessage="true" 
       - Compared tracked messages with those sent using my Service Bus Explorer.
    • SFANT, did you ever find a resolution to this?
    • Hi Glenn,
      In order to fix it, you have to put the address of the queue in the Headers.To property of the Message, before sending it to the queue.
      The To content should be in the form of "sb://<yoursbusDNS>/<SBNamespace>/<queuename>".
      I was not able to find which field should be filled in the Service bus explorer Send form because the TO field in the Sender tab is not working.
  • Message Addressing
    3 Posts | Last post March 18, 2014
    • Hi Paolo,
      First of all thank you for this great sample. I see you have put much effort in it, really appreciate it.
      I wonder if you already came across the following problem:
      When I send a message to the Queue to be picked up by BizTalk (with ServiceBus Explorer or your Client App) I see following warning appearing in BizTalk:
      The WCF service host at address "sb://xxxx/ServiceBusDefaultNamespace/biztalk/requestqueue" has received a Message addressed to "" which cannot be processed. If the HTTP transport was used, ensure that the HTTP Verb is correct.  
      Did you ever came across this problem? 
    • Update:
      Apparently it is working with your Client App. I only get above error when testing with ServiceBus Explorer.
    • Hi Gleen 
      thanks for the feedback. When using the Service Bus Explorer to send the message, make sure the payload is in correct format and above all make sure to select WCF from the Body Type dropdownlist! :) If you select String or Stream it will never go through!
  • BizTalk to SB 1.1
    3 Posts | Last post November 06, 2013
    • Hi Paulo,
      Would it be possible to integrate with service bus 1.1 from BizTalk 2103 using the same approach, possibly just replacing Microsoft.ServiceBus.dll v1.8 with v2.2?
    • Hi Dustyn
      The answer is yes: I did that already on my machine. :) However, you can't use Microsoft.ServiceBus.dll 2.2 as this is not compatible with the Service Bus 1.1. You have to use the Microsoft.ServiceBus.dll 2.1. I verified this with the product Group, so I'm 100% sure. In addition, my Service Bus Explorer tool doesn't work with the Service Bus 1.1 when using the Microsoft.ServiceBus.dll 2.2. Hope this helps!
    • Hi Paolo,
      Thanks very much for getting back to me. 
      I did manage to get it working with 2.1 as you say. I used Assembly Binding Redirection to redirect from (BTS 2013), to and I GAC'd ... as well as recompiling the WCFSolutionExtension bits with 2.1.0. 
      Kind Regards,
  • How to handle the service bus queue peeklock mode from biztalk server?
    2 Posts | Last post September 23, 2013
    • Hi Paolo 
      can the abandon or complete response be send back to a service bus queue from biztalk server in peek lock mode ?
    • Hi BC
      I suspect that the answer is, yes, you can, but only if you don't use the WCF-Custom adapter. If you want to use the PeekLock receive mode with WCF and the NetMessagingBinding, you need to explictly use the ReceiveContext class as shown below in the WCF service code:
      public class OrderService : IOrderService
          public void ReceiveOrder(Order order)
              // Get the BrokeredMessageProperty from the current OperationContext
              var incomingProperties = OperationContext.Current.IncomingMessageProperties;
              var property = incomingProperties[BrokeredMessageProperty.Name] as BrokeredMessageProperty;
              // Commit the receive operation
              ReceiveContext receiveContext;
              if (ReceiveContext.TryGet(incomingProperties, out receiveContext))
                  throw new InvalidOperationException(“An error occurred while processing an order.");
      In BizTalk, you should change the code of the BizTalkServiceInstance which is the web service class used by the WCF-Custom adapter. It comes without saying, that this is impossible. However, I never tried to execute this code in an extensivibility point such as a message inspector or a custom channel. You may try and let me know. :) There are two reasons for using the PeekLock receive mode: the first one is to avoid losing a message until the latter has been fully processed by the receiver. In BizTalk you may rephrase as "until the message has been persisted to the MessageBox Db". If this is your case, you can try to use the ReceiveContext in an extensibility point as I suggested above. If instead, you want to execute the Commit only after you fully processed the message, you should place te entire logic in the extensibility component. Hope this helps!
  • Minor fix to your code is required
    2 Posts | Last post July 25, 2013
    • In the BusinessLogic assembly there is the ResponseManager class. The GetEndpointBehaviorConfiguration() method needs to be modified to use bizTalkMessageInspector and not serviceBusMessageInspector. 
      The WCFServiceBusAndSolutionExtensions.config uses bizTalkMessageInspector and not serviceBusMessageInspector and therefore my machine.config was also using bizTalkMessageInspector.
      Once this modification is applied I managed to get the Dynamic orchestration with Topics working successfully.
      I consider myself quite an advanced BizTalk developer, but I found your example to be very useful. I especially liked all the custom WCF behaviors. Adding the listenUri was a master stroke :)
    • Hi Piers
      serviceBusMessageInspector was the name that I gave to the component in the cloud version of the solution. I changed the name of the componet to bizTalkMessageInspector but I forgot to change the GetEndpointBehaviorConfiguration method as you pointed out! Thanks for raising this up! I'll change the solution accordingly. Thanks for the great feedback, I'm happy you found my solution useful. :)
  • Enable transaction on NetMessagingBinding
    2 Posts | Last post July 25, 2013
    • Hi Paolo, I was the first one to ask questions on this thread.
      I use NetMessagingBinding send port to send messages to a queue. Then I have a receive location to pump out messages. The thing I've observed is sporadically messages could be lost at receive.
      I've enabled "Suspend request message on failure" in wcf config but it doesn't help. 
      The way I re-produce it is by sending 100 messages into a queue and when the rec. loc. pumps them out, I constantly re-start the rec. loc. By re-starting rec. loc many times, I could lose a couple of messages out of 100. 
      I'm wondering if transaction could make it robust?  If it's the right approach, how would I enable the transaction in your code?
      Thank-you! vt
    • Hi vt, a way to avoid losing messages would be using PeekLock receive mode, but there's no way to specify this option when using WCF with the NetMessagingBinding. Remember that the Receive operation is not transactional, while the Complete operation is transactional. So, when using a the Service Bus .NET API (Microsoft.ServiceBus.dll) and in particular a MessageReceiver or a QueueClient or a SubscriptionClient to receive a message, if you want to use transactions, you need to use the ReceiveMode = PeekLock. Hope this helps. :)
1 - 10 of 15 Items