Genericizing the GenericProxy<T>

Tags: .NET, WinFX

A few days ago, Guy Burstein wrote a entry on avoiding design-time generated proxies by extending the ClientBase class to create a GenericProxy. This proxy uses the client binding data in the app.config file to auto-create an appropriate proxy when the interface is shared by both client and server.

I gleefully lifted that piece of code for use in my emerging WCF project, but needed it a bit more generic than that. Seeing as I currently have no need for any fine-tuned configuration, I can get by with a GenericProxy that explicitly gets the Binding and EndpointAddress of the service in question. Since the ClientBase already supports this, I just have to make sure that my GenericProxy exposes this too:

public GenericProxy(Binding binding, EndpointAddress address)
            : base(binding, address)
{ }


Which now allows me to instantiate my proxy like this:

EndpointAddress address = new EndpointAddress(serviceUri);
Binding binding = new NetTcpBinding();
GenericProxy configurationProxy = new GenericProxy(binding, address);

As long as I don't need any customizations beyond the basic binding and URI, I don't need any configuration files whatsoever in my client.

No Comments