Click here to Skip to main content
15,891,423 members
Articles / Programming Languages / C#

WS-Discovery for WCF

Rate me:
Please Sign up or sign in to vote.
4.95/5 (31 votes)
27 Nov 2008CPOL12 min read 139.7K   3.3K   86  
This article describes the design, implementation, and usage of WS-Discovery for Windows Communication Foundation (WCF).
using System;

namespace Masieri.ServiceModel.WSDiscovery.Activation
{
    /// <summary>
    /// Factory for creating Dynamic proxy instances
    /// <code>
    /// TestClasses.SimpleClass testClass = new TestClasses.SimpleClass();
    /// TestClasses.ISimpleInterface testClassProxy = (TestClasses.ISimpleInterface) DynamicProxyFactory.Instance.CreateProxy(testClass, new InvocationDelegate(InvocationHandler));
    /// testClassProxy.Method1();
    /// </code>
    /// <see cref="IDynamicProxy"/>
    /// </summary>
    class DynamicProxyFactory
    {
        private static DynamicProxyFactory _factory = new DynamicProxyFactory();

        private DynamicProxyFactory()
        {
        }

        /// <summary>
        /// Get the instance of the factory (singleton)
        /// </summary>
        public static DynamicProxyFactory Instance
        {
            get { return _factory; }
        }

        /// <summary>
        /// Create a proxy for the target object
        /// </summary>
        /// <param name="target">The object to create a proxy for</param>
        /// <param name="_invocationHandler">The invocation handler for the proxy</param>
        /// <returns>The dynamic proxy instance</returns>
        public object CreateProxy(object target, InvocationDelegate invocationHandler)
        {
            return CreateProxy(target, invocationHandler, false, null);
        }

        /// <summary>
        /// Create a proxy for the target object
        /// </summary>
        /// <param name="target">The object to create a proxy for</param>
        /// <param name="_invocationHandler">The invocation handler for the proxy</param>
        /// <param name="_strict">Indicates if the cast support should be _strict. If _strict is true all casts are checked before being performed</param>
        /// <returns>The dynamic proxy instance</returns>
        public object CreateProxy(object target, InvocationDelegate invocationHandler, bool strict)
        {
            return CreateProxy(target, invocationHandler, strict, null);
        }

        /// <summary>
        /// Create a proxy for the target object
        /// </summary>
        /// <param name="target">The object to create a proxy for</param>
        /// <param name="_invocationHandler">The invocation handler for the proxy</param>
        /// <param name="_strict">Indicates if the cast support should be _strict. If _strict is true all casts are checked before being performed. The supportedType list will enabled support for more interfaces than the target object supports</param>
        /// <param name="_supportedTypes">List of types that are supported for casts. Is only checked if _strict is true.</param>
        /// <returns>The dynamic proxy instance</returns>
        public object CreateProxy(object target, InvocationDelegate invocationHandler, bool strict, Type[] supportedTypes)
        {
            return new DynamicProxyImpl(target, invocationHandler, strict, supportedTypes).GetTransparentProxy();
        }
    }
}

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
Software Developer
Italy Italy
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions