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.Net;
using System.Collections.Generic;
using System.Diagnostics;
using System.Security.Principal;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using Microsoft.ServiceBus;
#endregion

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

        private const string MessageFormat = "[TokenProviderEndpointBehavior] TokenProvider = {0}.";
        #endregion

        #region Private Fields
        private readonly string userName;
        private readonly string password;
        private readonly string domain;
        private readonly string stsEndpoint;
        private readonly TokenProviderType tokenProviderType;
        private readonly bool isTrackingEnabled;
        #endregion

        #region Public Constructors
        /// <summary>
        /// Initializes a new instance of the TokenProviderEndpointBehavior class.
        /// </summary>
        /// <param name="userName">The user name associated with the credentials.</param>
        /// <param name="password">The password for the user name associated with the credentials.</param>
        /// <param name="domain">The domain associated with these credentials.</param>
        /// <param name="stsEndpoint">The uri of the sts endpoint.</param>
        /// <param name="tokenProviderType">The type of the token provider.</param>
        /// <param name="isTrackingEnabled">A boolean value indicating whether tracking is enabled.</param>
        public TokenProviderEndpointBehavior(string userName, 
                                             string password,
                                             string domain,
                                             string stsEndpoint,
                                             TokenProviderType tokenProviderType,
                                             bool isTrackingEnabled)
        {
            this.userName = userName;
            this.password = password;
            this.domain = domain;
            this.stsEndpoint = stsEndpoint;
            this.tokenProviderType = tokenProviderType;
            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)
        {
            var stsUri = new Uri(stsEndpoint);
            var stsUris = new List<Uri> { stsUri };
            var useCurrentUser = string.IsNullOrEmpty(userName) ||
                                 string.IsNullOrEmpty(password) ||
                                 string.IsNullOrEmpty(domain);
            bindingParameters.Add(new TransportClientEndpointBehavior
                {
                    TokenProvider = tokenProviderType == TokenProviderType.WindowsTokenProvider ?
                                    useCurrentUser ? TokenProvider.CreateWindowsTokenProvider(stsUris) : TokenProvider.CreateWindowsTokenProvider(stsUris, new NetworkCredential(userName, password, domain)) :
                                    TokenProvider.CreateOAuthTokenProvider(stsUris, new NetworkCredential(userName, password, domain))
                });
            Trace.WriteLineIf(isTrackingEnabled, string.Format(MessageFormat, tokenProviderType));
        }

        /// <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
    }
}