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

namespace DynamicWCFFactory
{
    /// <summary>
    /// Provide the functionalities to read and write the configuration of a service to discover through UDDI.
    /// </summary>
    public class ServiceDiscoveryConfigurationSection : ConfigurationSection
    {
        #region Fields

        /// <summary>
        /// Internal flag to disable property setting.
        /// </summary>
        private static bool _isReadOnlySection = false;

        /// <summary>
        /// The collection (property bag) that contains the section properties.
        /// </summary>
        private static ConfigurationPropertyCollection _propertyBag;

        /// <summary>
        /// The URL of the directory services property.
        /// </summary>
        private static readonly ConfigurationProperty _directoryURL = new ConfigurationProperty("DirectoryURL",
            typeof(string), null,
            ConfigurationPropertyOptions.None);

        /// <summary>
        /// The Service Key property.
        /// </summary>
        private static readonly ConfigurationProperty _name = new ConfigurationProperty("Name",
            typeof(string), null,
            ConfigurationPropertyOptions.None);

        /// <summary>
        /// The Service Key property.
        /// </summary>
        private static readonly ConfigurationProperty _serviceKey = new ConfigurationProperty("ServiceKey",
            typeof(string), null,
            ConfigurationPropertyOptions.None);

        /// <summary>
        /// The TModel Key property.
        /// </summary>
        private static readonly ConfigurationProperty _tModelKey = new ConfigurationProperty("TModelKey",
            typeof(string), null,
            ConfigurationPropertyOptions.IsRequired);

        #endregion

        #region Private methods

        /// <summary>
        /// Throws an exception if the configuration is read-only.
        /// </summary>
        /// <param name="propertyName"></param>
        private void ThrowExceptionIfReadOnly(string propertyName)
        {
            if (_isReadOnlySection)
                throw new ConfigurationErrorsException("The property " + propertyName + " is read only.");
        }

        #endregion

        #region Public properties

        /// <summary>
        /// Gets or sets the URL of the UDDI directory service.
        /// </summary>
        [StringValidator(InvalidCharacters = " ~!@#$%^&*()[]{};'\"|\\", MinLength = 1, MaxLength = 128)]
        public string DirectoryURL
        {
            get { return (string)this[_directoryURL]; }
            set
            {
                ThrowExceptionIfReadOnly("DirectoryURL");
                this[_directoryURL] = value;
            }
        }

        /// <summary>
        /// Gets or sets the name of the configuration section.
        /// </summary>
        [StringValidator(InvalidCharacters = " ~!@#$%^&*()[]{}/;'\"|\\", MinLength = 1, MaxLength = 128)]
        public string Name
        {
            get { return (string)this[_name]; }
            set
            {
                ThrowExceptionIfReadOnly("Name");
                this[_name] = value;
            }
        }

        /// <summary>
        /// Gets or sets the Service Key.
        /// </summary>
        [StringValidator(InvalidCharacters = " ~!@#$%^&*()[]{}/;'\"|\\", MinLength = 1, MaxLength = 128)]
        [RegexStringValidator(@"^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}$")]
        public string ServiceKey
        {
            get { return (string)this[_serviceKey]; }
            set
            {
                ThrowExceptionIfReadOnly("ServiceKey");
                this[_serviceKey] = value;
            }
        }

        /// <summary>
        /// Gets or sets the TModel Key of the service.
        /// </summary>
        [StringValidator(InvalidCharacters = " ~!@#$%^&*()[]{}/;'\"|\\", MinLength = 1, MaxLength = 128)]
        [RegexStringValidator(@"^uuid:(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}$")]
        public string TModelKey
        {
            get { return (string)this[_tModelKey]; }
            set
            {
                ThrowExceptionIfReadOnly("TModelKey");
                this[_tModelKey] = value;
            }
        }

        /// <summary>
        /// This is a key customization. 
        /// <remarks>Gets the initialized property bag.</remarks>
        /// </summary>
        protected override ConfigurationPropertyCollection Properties
        {
            get { return _propertyBag; }
        }

        #endregion

        #region Ctor

        /// <summary>
        /// Initializes a new instance of the ServiceDiscoveryConfigurationSection class.
        /// </summary>
        public ServiceDiscoveryConfigurationSection()
        {
            // Create a new instance of the ConfigurationPropertyCollection class.
            _propertyBag = new ConfigurationPropertyCollection();

            // Adds the properties to the property bag.
            _propertyBag.Add(_directoryURL);
            _propertyBag.Add(_name);
            _propertyBag.Add(_serviceKey);
            _propertyBag.Add(_tModelKey);
        }

        /// <summary>
        /// 
        /// </summary>
        ~ServiceDiscoveryConfigurationSection()
        {
            Dispose();
        }

        #endregion

        #region IDisposable implementation

        /// <summary>
        /// 
        /// </summary>
        public virtual void Dispose()
        {
            _propertyBag = null;
        }

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