Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Integrating WCF Services into UDDI based enterprise SOA

, 27 Jan 2009 CPOL
Shows how to integrate WCF services into a UDDI based SOA. This includes the discovery of WCF services at runtime and the runtime configuration of the client.
DynamicWCFFactory.zip
DynamicWCFFactory
DynamicWCFFactory
Behaviours
bin
Debug
Configuration
Properties
DynamicWCFFactory.gpState
DynamicWCFFactory.vsmdi
DynamicWCFFactoryTests
bin
Debug
Properties
Service References
ServiceReference
configuration.svcinfo
configuration91.svcinfo
DynamicWCFFactoryTests.ServiceReference.CompositeType.datasource
Reference.svcmap
Service1.disco
Service1.wsdl
LocalTestRun.testrunconfig
TestResults
UDDIServiceFactory
bin
Debug
Configuration
Lib
Microsoft.Uddi.dll
Properties
WcfService
App_Data
bin
Properties
Service1.svc
WcfService.csproj.user
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Reflection;
using System.ServiceModel.Channels;
using System.ServiceModel.Configuration;

namespace DynamicWCFFactory
{
    /// <summary>
    /// Provides methods to discover and configure various aspects of a WCF client.
    /// </summary>
    public class BindingConfigurationHelper
    {
        #region Members

        /// <summary>
        /// The configuration from the application configuration file.
        /// </summary>
        private System.Configuration.Configuration _appConfig = null;

        /// <summary>
        /// The list of key-value pair, property name and property value, used to configure a <see cref="Binding"/>.
        /// </summary>
        public class BindingProperties : Dictionary<string, IConvertible>
        {
        }

        #endregion

        #region Private methods

        /// <summary>
        /// Sets the properties of the binding by applying the properties from the property list.
        /// </summary>
        /// <param name="binding">The <see cref="System.ServiceModel.Channels.Binding"/> to configure.</param>
        /// <param name="properties">The list of properties to apply</param>
        private void SetBindingProperties(Binding binding, BindingProperties properties)
        {
            CustomBinding customBinding = binding as CustomBinding;

            if (customBinding != null)
            {
                foreach (BindingElement element in customBinding.Elements)
                {
                    Type elementType = element.GetType();
                    foreach (KeyValuePair<string, IConvertible> _keyValue in properties)
                    {
                        // Retrieve the PropertyInfo for the specified property.
                        PropertyInfo _propertyInfo = elementType.GetProperty(_keyValue.Key, BindingFlags.Instance | BindingFlags.Public);
                        if (null != _propertyInfo)
                        {
                            try
                            {
                                _propertyInfo.SetValue(binding, _keyValue.Value, null);
                            }
                            catch
                            {
                                // HACK: the catch block is intentionally doing nothing to
                                // allow the loop to continue processing the property list.
                            }
                        }
                    }
                }
            }

            // Retrieve the type of the binding.
            Type _bindingType = binding.GetType();

            // Process the collection of properties to set.
            foreach (KeyValuePair<string, IConvertible> _keyValue in properties)
            {
                // Retrieve the PropertyInfo for the specified property.
                PropertyInfo _propertyInfo = _bindingType.GetProperty(_keyValue.Key, BindingFlags.Instance | BindingFlags.Public);
                if (null != _propertyInfo)
                {
                    try
                    {
                        _propertyInfo.SetValue(binding, _keyValue.Value, null);
                    }
                    catch
                    {
                        // HACK: the catch block is intentionally doing nothing to
                        // allow the loop to continue processing the property list.
                    }
                }
            }
        }

        
        #endregion

        #region Public methods

        /// <summary>
        /// Configures the given <see cref="System.ServiceModel.Channels.Binding"/> using the key-value pairs from the <see cref="BindingProperties"/> list.
        /// </summary>
        /// <param name="binding">The  <see cref="System.ServiceModel.Channels.Binding"/> to configure.</param>
        /// <param name="properties">The key-value pair of properties used to configure the new <see cref="System.ServiceModel.Channels.Binding"/>.</param>
        public void ConfigureClientBinding(Binding binding, BindingProperties properties)
        {
            // Set the properties of the new binding.
            SetBindingProperties(binding, properties);
        }


        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Tobias Manthey
Architect
Germany Germany
being IT-Engineer since 1995 I am freelancing since then. From networks to programming, from system administration to DBA, from AIX to Windows I offer a wide range of IT-Skill's without considering me the ultimate expert in each area.
I try to avoid complexity wherever I can and so my philosophy is to strictly follow KISS principles.

| Advertise | Privacy | Mobile
Web03 | 2.8.141015.1 | Last Updated 27 Jan 2009
Article Copyright 2009 by Tobias Manthey
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid