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.IO;
using System.Xml;
using System.Diagnostics;
using System.Configuration;
#endregion

namespace Microsoft.WindowsAzure.CAT.Samples.ServiceBusForWindowsServer.BusinessLogic
{
    [Serializable]
    public class LogHelper
    {
        #region Private Constants
        //***************************
        // Private Constants
        //***************************
        private const string CalculatorResponseNamespace = "http://windowsazure.cat.microsoft.com/samples/servicebusforwindowsserver";
        private const string DebugParameter = "debug";
        #endregion

        #region Private Static Fields
        //***************************
        // Private Static Fields
        //***************************
        private static bool debug = true;
        #endregion

        #region Static Constructor
        //***************************
        // Static Constructor
        //***************************

        /// <summary>
        /// Static constructor.
        /// </summary>
        static LogHelper()
        {
            try
            {
                string debugParameter = ConfigurationManager.AppSettings[DebugParameter];
                if (!string.IsNullOrEmpty(debugParameter))
                {
                    if (!bool.TryParse(debugParameter, out debug))
                    {
                        debug = true;
                    }
                }
            }
            catch (Exception)
            {
            }
        }
        #endregion

        #region Public Methods
        /// <summary>
        /// Writes a message to the trace listeners in the System.Diagnostics.Trace.Listeners collection.
        /// </summary>
        /// <param name="message">The message to write.</param>
        public void WriteLine(string message)
        {
            if (debug)
            {
                Trace.WriteLine(message);
            }
        }

        /// <summary>
        /// Writes a message to the trace listeners in the System.Diagnostics.Trace.Listeners collection.
        /// </summary>
        /// <param name="format">A string format.</param>
        /// <param name="args">The string format parameters</param>
        public void WriteLine(string format, params object[] args)
        {
            if (debug)
            {
                Trace.WriteLine(string.Format(format, args));
            }
        }

        /// <summary>
        /// Generates a stream containing the exception message.
        /// </summary>
        /// <param name="ex">An exception.</param>
        /// <returns>The stream containing the exception message.</returns>
        public Stream GenerateErrorStream(Exception ex)
        {
            return GenerateErrorStream(ex != null ? ex.Message : null);
        }

        /// <summary>
        /// Generates a stream containing the exception message.
        /// </summary>
        /// <param name="exception">An exception message.</param>
        /// <returns>The stream containing the exception message.</returns>
        public Stream GenerateErrorStream(string exception)
        {
            try
            {
                var stream = new MemoryStream();
                using (var writer = XmlWriter.Create(stream))
                {
                    writer.WriteStartDocument();
                    writer.WriteStartElement("CalculatorResponse", CalculatorResponseNamespace);
                    writer.WriteStartElement("Status", CalculatorResponseNamespace);
                    writer.WriteString(exception);
                    writer.WriteEndElement();
                    writer.WriteEndElement();
                }
                stream.Seek(0, SeekOrigin.Begin);
                return stream;
            }
            catch (Exception)
            {
            }
            return null;
        }
        #endregion
    }
}