Click here to Skip to main content
15,896,606 members
Articles / Programming Languages / C#

Integrating WCF Services into UDDI based enterprise SOA

Rate me:
Please Sign up or sign in to vote.
4.87/5 (16 votes)
27 Jan 2009CPOL18 min read 69.6K   749   42  
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.
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;

namespace UDDIServiceFactory.Configuration
{
    /// <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)


Written By
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.

Comments and Discussions