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
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;
using System.Configuration;
using System.Linq;

namespace DynamicWCFFactory
{
    /// <summary>
    /// Provides methods to retrieve a <see cref="ServiceDiscoveryConfigurationSection"/> section
    /// from the application configuration file.
    /// </summary>
    public class ServiceDiscoveryConfigurationHelper
    {
        #region Fields

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

        #endregion

        #region Internal methods

        /// <summary>
        /// Returns all the configuration groups of the given type.
        /// </summary>
        /// <typeparam name="T">The type of the configuration section group to return</typeparam>
        /// <returns>A <see cref="ConfigurationSectionGroup"/> matching the given type.</returns>
        internal IEnumerable Group<T>() where T : class, new()
        {
            // Selectively retrieve the requested configuration sections.
            IEnumerable _groupQuery = _appConfig.SectionGroups.OfType<T>();
            foreach (ConfigurationSectionGroup _group in _groupQuery)
            {
                // Return the result to the caller.
                yield return _group;
            }
        }

        /// <summary>
        /// Returns all the configuration sections of the given type matching the given name.
        /// </summary>
        /// <typeparam name="T">The type of the sections to return.</typeparam>
        /// <param name="sectionName">The name of the section searched for.</param>
        /// <returns>A <see cref="ConfigurationSection"/> matching the given parameters.</returns>
        internal T Section<T>(string sectionName) where T : ServiceDiscoveryConfigurationSection
        {
            // Browse through all configuration groups.
            foreach (ConfigurationSectionGroup _group in _appConfig.SectionGroups)
            {
                // Selectively retrieve the requested configuration sections.
                IEnumerable _sectionQuery = _group.Sections.OfType<T>();
                foreach (T _section in _sectionQuery)
                {
                    // If the name of the section matches the given section name.
                    if (StringComparer.OrdinalIgnoreCase.Equals(_section.Name, sectionName))
                    {
                        // Return the result to the caller.
                        return _section as T;
                    }
                }
            }
            return default(T);
        }

        /// <summary>
        /// Returns all the configuration sections of the given type.
        /// </summary>
        /// <typeparam name="T">The type of the configuration section to return</typeparam>
        /// <returns>A <see cref="ConfigurationSection"/> matching the given type.</returns>
        internal IEnumerable Section<T>() where T : ServiceDiscoveryConfigurationSection
        {
            // Browse through all configuration groups.
            foreach (ConfigurationSectionGroup _group in _appConfig.SectionGroups)
            {
                // Selectively retrieve the requested configuration sections.
                IEnumerable _sectionQuery = _group.Sections.OfType<T>();
                foreach (ConfigurationSection _section in _sectionQuery)
                {
                    // Return the result to the caller.
                    yield return _section;
                }
            }
        }

        #endregion

        #region Public methods

        /// <summary>
        /// Returns a <see cref="ServiceDiscoveryConfigurationSection"/> matching the given name.
        /// </summary>
        /// <param name="name">The name of the <see cref="ServiceDiscoveryConfigurationSection"/> to return.</param>
        /// <returns>The <see cref="ServiceDiscoveryConfigurationSection"/> matching the given name.</returns>
        public ServiceDiscoveryConfigurationSection Section(string name)
        {
            // Browse through all configuration groups.
            foreach (ConfigurationSectionGroup _sectionGroups in _appConfig.SectionGroups)
            {
                // Return the first configuration section matching the given name.
                var _section = (from _sections in _sectionGroups.Sections.OfType<ServiceDiscoveryConfigurationSection>()
                                where _sections.Name == name
                                select _sections).FirstOrDefault();
                if (null!=_section)
                    return _section;
            }
            return null;
        }

        #endregion

        #region Ctor

        /// <summary>
        /// Initializes a new instance of the ServiceDiscoveryConfigurationHelper class.
        /// </summary>
        public ServiceDiscoveryConfigurationHelper()
        {
            // Get the application configuration file.
            _appConfig = ConfigurationAgent.OpenExeConfiguration(ConfigurationUserLevel.None);
        }

        #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
Web04 | 2.8.140902.1 | Last Updated 27 Jan 2009
Article Copyright 2009 by Tobias Manthey
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid