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,705 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.Xml;
using System.Collections.Generic;
#endregion


namespace Microsoft.WindowsAzure.CAT.Samples.ServiceBusForWindowsServer.Client
{
    public static class ConversionHelper
    {
        #region Private Constants
        private const string TypeNotSupported = "Type not supported: {0}";
        #endregion

        #region Static Fields
        private static Dictionary<Type, string> clrToEDMMappingDictionary = new Dictionary<Type, string>();
        #endregion

        #region Static Constructor
		static ConversionHelper()
        {
            clrToEDMMappingDictionary.Add(typeof(byte), "Edm.Byte");
            clrToEDMMappingDictionary.Add(typeof(short), "Edm.Int16");
            clrToEDMMappingDictionary.Add(typeof(int), "Edm.Int32");
            clrToEDMMappingDictionary.Add(typeof(long), "Edm.Int64");
            clrToEDMMappingDictionary.Add(typeof(float), "Edm.Single");
            clrToEDMMappingDictionary.Add(typeof(double), "Edm.Double");
            clrToEDMMappingDictionary.Add(typeof(decimal), "Edm.Decimal");
            clrToEDMMappingDictionary.Add(typeof(byte[]), "Edm.Binary");
            clrToEDMMappingDictionary.Add(typeof(Guid), "Edm.Guid");
            clrToEDMMappingDictionary.Add(typeof(DateTime), "Edm.DateTime");
            clrToEDMMappingDictionary.Add(typeof(bool), "Edm.Boolean");
        } 
	    #endregion

        #region Public Static Methods
        public static object MapEDMTypeToCLRType(string type, string value, bool isNull)
        {
            if (isNull)
            {
                return null;
            }
            if (string.IsNullOrEmpty(type))
            {
                return value;
            }
            switch (type)
            {
                case "Edm.String":
                    return value;
                case "Edm.Byte":
                    return Convert.ChangeType(value, typeof(byte));
                case "Edm.SByte":
                    return Convert.ChangeType(value, typeof(sbyte));
                case "Edm.Int16":
                    return Convert.ChangeType(value, typeof(short));
                case "Edm.Int32":
                    return Convert.ChangeType(value, typeof(int));
                case "Edm.Int64":
                    return Convert.ChangeType(value, typeof(long));
                case "Edm.Single":
                    return Convert.ChangeType(value, typeof(float));
                case "Edm.Double":
                    return Convert.ChangeType(value, typeof(double));
                case "Edm.Boolean":
                    return Convert.ChangeType(value, typeof(bool));
                case "Edm.Decimal":
                    return Convert.ChangeType(value, typeof(decimal));
                case "Edm.DateTime":
                    return XmlConvert.ToDateTime(value, XmlDateTimeSerializationMode.RoundtripKind);
                case "Edm.Binary":
                    return Convert.FromBase64String(value);
                case "Edm.Guid":
                    return new Guid(value);
            }
            throw new NotSupportedException(string.Format(TypeNotSupported, type));
        }

        public static object MapStringTypeToCLRType(string type, object value)
        {
            if (string.IsNullOrEmpty(type))
            {
                return value;
            }
            switch (type)
            {
                case "String":
                    return (value as string).Trim();
                case "Byte":
                    return Convert.ChangeType(value, typeof(byte));
                case "Int16":
                    return Convert.ChangeType(value, typeof(short));
                case "Int32":
                    return Convert.ChangeType(value, typeof(int));
                case "Int64":
                    return Convert.ChangeType(value, typeof(long));
                case "Single":
                    return Convert.ChangeType(value, typeof(float));
                case "Double":
                    return Convert.ChangeType(value, typeof(double));
                case "Boolean":
                    return Convert.ChangeType(value, typeof(bool));
                case "Decimal":
                    return Convert.ChangeType(value, typeof(decimal));
                case "Guid":
                    return new Guid(value as string);
            }
            throw new NotSupportedException(string.Format(TypeNotSupported, type));
        }

        public static string MapCLRTypeToEDMType(Type type)
        {
            if (type != null &&
                clrToEDMMappingDictionary.ContainsKey(type))
            {
                return clrToEDMMappingDictionary[type];
            }
            return null;
        } 
        #endregion
    }
}