Skip to main content

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
(6)
1,708 times
Add to favorites
6/20/2014
E-mail Twitter del.icio.us Digg Facebook

Solution explorer

C#
#region Copyright
//=======================================================================================
//Microsoft Windows Server AppFabric Customer Advisory Team (CAT)  
//
// This sample is supplemental to the technical guidance published on the community
// blog at http://blogs.msdn.com/paolos. 
// 
// Author: Paolo Salvatori
//=======================================================================================
// Copyright © 2011 Microsoft Corporation. All rights reserved.
// 
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 
// EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF 
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. YOU BEAR THE RISK OF USING IT.
//=======================================================================================
#endregion

#region Using Directives
using System;
using System.Diagnostics;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;

#endregion

namespace Microsoft.WindowsAzure.CAT.Samples.ServiceBusForWindowsServer.ListenUri
{
    public class ListenUriEndpointBehavior : IEndpointBehavior
    {
        #region Private Constants
        //***************************
        // Constants
        //***************************

        private const string ListerUriMessageFormat = "[ListenUriEndpointBehavior] ListenUri = [{0}].";
        #endregion

        #region Private Fields
        private readonly string listenUri;
        private readonly bool isTrackingEnabled;
        #endregion

        #region Public Constructors
        /// <summary>
        /// Initializes a new instance of the ListenUriEndpointBehavior class.
        /// </summary>
        /// <param name="listenUri">The URI at which the service endpoint listens</param>
        /// <param name="isTrackingEnabled">A boolean value indicating whether tracking is enabled</param>
        public ListenUriEndpointBehavior(string listenUri, bool isTrackingEnabled)
        {
            this.listenUri = listenUri;
            this.isTrackingEnabled = isTrackingEnabled;
        }
        #endregion

        #region IEndpointBehavior Members
        /// <summary>
        /// Implement to pass data at runtime to bindings to support custom behavior.
        /// </summary>
        /// <param name="endpoint">The endpoint to modify.</param>
        /// <param name="bindingParameters">The objects that binding elements require to support the behavior.</param>
        void IEndpointBehavior.AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
        {
            if (endpoint != null &&
                !String.IsNullOrEmpty(listenUri))
            {
                // Read the binding elements from the original binding
                var bindingElementCollection = endpoint.Binding.CreateBindingElements();
                // Create an array of binding elements
                var bindingElementArray = new BindingElement[bindingElementCollection.Count + 1];
                // Add an instance of the ListenUriBindingElement as first binding element of the array
                bindingElementArray[0] = new ListenUriBindingElement(listenUri);
                // Copy the binding elements of the original binding to the array
                bindingElementCollection.CopyTo(bindingElementArray, 1);
                // Create a custom binding with the same binding elements as the original
                // binding with the addition of the custom binding as first item
                var customBinding = new CustomBinding(bindingElementArray)
                                        {
                                            CloseTimeout = endpoint.Binding.CloseTimeout,
                                            OpenTimeout = endpoint.Binding.OpenTimeout,
                                            ReceiveTimeout = endpoint.Binding.ReceiveTimeout,
                                            SendTimeout = endpoint.Binding.SendTimeout,
                                            Name = endpoint.Binding.Name,
                                            Namespace = endpoint.Binding.Namespace
                                        };
                //Replace the original binding with the newly created binding
                endpoint.Binding = customBinding;
                Trace.WriteLineIf(isTrackingEnabled,
                                  string.Format(ListerUriMessageFormat,
                                                listenUri));
            }
        }

        /// <summary>
        /// Implements a modification or extension of the client across an endpoint.
        /// </summary>
        /// <param name="endpoint">The endpoint that is to be customized.</param>
        /// <param name="clientRuntime">The client runtime to be customized.</param>
        void IEndpointBehavior.ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
        {
        }

        /// <summary>
        /// Implements a modification or extension of the service across an endpoint.
        /// </summary>
        /// <param name="endpoint">The endpoint that exposes the contract.</param>
        /// <param name="endpointDispatcher">The endpoint dispatcher to be modified or extended.</param>
        void IEndpointBehavior.ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
        {
        }

        /// <summary>
        /// Implement to confirm that the endpoint meets some intended criteria.
        /// </summary>
        /// <param name="endpoint">The endpoint to validate.</param>
        void IEndpointBehavior.Validate(ServiceEndpoint endpoint)
        {
        }
        #endregion
    }
}