>
 Sunday, October 02, 2005
« Building a machine with the latest WinFX... | Main | WCF Coding Practices: Base Addresses and... »

I thought I'd share this observation in the interest of coding practices for the WCF. For client applications invoking services, you'll see lots of samples already out there that use the following syntax:


ChannelFactory<IService> factory = new ChannelFactory<IService>("");
IService proxy = factory.CreateChannel();

string s = proxy.HelloIndigo();


But, the proxy generated for you, that inherits ClientBase<T>, will handle creating the channel for you so you can use syntax like this:


using (ServiceProxy proxy = new ServiceProxy(""))
{
  string s = proxy.HelloIndigo();
}


Besides its relative simplicity, another slant in favor of using the proxy generated for your service is that its base class implements IDisposable, therefore you can use the using statement to expedite cleanup of channel resources.

There are probably cases where you will need to interact with the channel directly, though none come to mind at the moment...for the most part you should be able to configure the channel using binding configurations.


 

10/2/2005 4:33 AM Indigo  | Comments [2]  |  View reactions  |  Trackback
    ON THIS PAGE
    SEARCH
    CATEGORIES
    ARCHIVES
    BLOGROLL

Designed by NUKEATION STUDIOS