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.ServiceModel.Channels;
using System.ServiceModel.Description;
#endregion

namespace Microsoft.WindowsAzure.CAT.Samples.ServiceBusForWindowsServer.ListenUri
{
    /// <summary>
    /// At runtime, this binding element can be used to initialize
    /// the listenUri property of the service endpoint.
    /// </summary>
    class ListenUriBindingElement : BindingElement
    {
        #region Private Fields
        private readonly string listenUri;
        #endregion

        #region Public Constructor
        /// <summary>
        /// Initializes a new instance of the ListenUriBindingElement class.
        /// </summary>
        /// <param name="listenUri">A BindingElement object that is a deep clone of the original.</param>
        public ListenUriBindingElement(string listenUri)
        {
            this.listenUri = listenUri;
        }
        #endregion

        #region BindingElement Members
        /// <summary>
        /// returns a copy of the binding element object.
        /// </summary>
        /// <returns></returns>
        public override BindingElement Clone()
        {
            return new ListenUriBindingElement(listenUri);
        }

        /// <summary>
        /// Returns a typed object requested, if present, from the appropriate layer in the binding stack.
        /// </summary>
        /// <typeparam name="T">The typed object for which the method is querying.</typeparam>
        /// <param name="context">The BindingContext for the binding element.</param>
        /// <returns>The typed object T requested if it is present or nullif it is not present.</returns>
        public override T GetProperty<T>(BindingContext context)
        {
            return context.GetInnerProperty<T>();
        }

        /// <summary>
        /// Returns a value that indicates whether the binding element can build a channel factory for a specific type of channel.
        /// </summary>
        /// <typeparam name="TChannel">The type of channel the channel factory produces.</typeparam>
        /// <param name="context">The BindingContext that provides context for the binding element.</param>
        /// <returns>true if the IChannelFactory<TChannel/>of type TChannel can be built by the binding element; otherwise, false.</returns>
        public override bool CanBuildChannelFactory<TChannel>(BindingContext context)
        {
            return false;
        }

        /// <summary>
        /// Initializes a channel factory for producing channels of a specified type from the binding context.
        /// </summary>
        /// <typeparam name="TChannel">The type of channel the factory builds.</typeparam>
        /// <param name="context">The BindingContext that provides context for the binding element.</param>
        /// <returns>The IChannelFactory<TChannel/>of type TChannel initialized from the context. </returns>
        public override IChannelFactory<TChannel> BuildChannelFactory<TChannel>(BindingContext context)
        {
            throw new NotSupportedException();
        }

        /// <summary>
        /// Returns a value that indicates whether the binding element can build a channel listener for a specific type of channel.
        /// </summary>
        /// <typeparam name="TChannel">The type of channel listener to build.</typeparam>
        /// <param name="context">The BindingContext for the binding element.</param>
        /// <returns>true if a channel listener of the specified type can be built; otherwise, false. The default is false. </returns>
        public override bool CanBuildChannelListener<TChannel>(BindingContext context)
        {
            return context.CanBuildInnerChannelListener<TChannel>();
        }

        /// <summary>
        /// Initializes a channel listener for producing channels of a specified type from the binding context.
        /// </summary>
        /// <typeparam name="TChannel">The type of channel that the listener is built to accept.</typeparam>
        /// <param name="context">The BindingContext for the binding element.</param>
        /// <returns>The IChannelListener<TChannel/>of type IChannel initialized from the context.</returns>
        public override IChannelListener<TChannel> BuildChannelListener<TChannel>(BindingContext context)
        {
            if (!string.IsNullOrEmpty(listenUri))
            {
                context.ListenUriBaseAddress = new Uri(listenUri);
                context.ListenUriMode = ListenUriMode.Explicit;
            }
            return context.BuildInnerChannelListener<TChannel>();
        } 
        #endregion
    }
}