Manually writing proxies

Posted: February 23, 2011 in WCF
Tags: , ,

Whoever comes from a soap service background always may have an assumption that for generating proxies you need to rely on svcutil.exe.If you think so,this assumption is wrong.You can create a proxy manually too.I am explaining here how you can do for a WCF service.  

The proxy class derives from the class ClientBase<T> & ClientBase<T> accepts a single generic type parameter which is the service contract this proxy encapsulates. Say you have a servicecontract IVendorServices,then ClientBase<T> gets replaced with ClientBase<IVendorServices>.

    public interface IVendorServices

        [WebGet(UriTemplate = "v1/Ping")]
        string Ping();

public class VendorServices : IVendorServices

        [Description("Service for Testing")]
        public string Ping()
            return DateTime.Now.ToString("yyyy-MM-dd_HH:mm:ss:fffffffK");


public class VendorProxy : ClientBase<IVendorServices>, IVendorServices
        public VendorProxy()
        #region IVendorServices Members

        public string Ping()
            return Channel.Ping();


After you write the proxy class,if you place mouse over the interface name,it will create the members of class automatically.The Channel property of ClientBase<T> is of the type of  T parameter passed & if you write Channel.Ping(),it delegates the call to the method’s actual implementation & returns you the result.

 Hope you got some idea on how it works 🙂

  1. Joy says:

    Channel is of type IVendorServices .Where is the concrete class for this interface ? Is it also created dynamically?

  2. Anupama says:

    I did not understand what you have meant by dynamically here.VendorServices class implements methods of IVendorServices..Ya Channel is of type IVendorServices for that proxy.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s