This project is read-only.

Client Channel

The client channel represents infrastructure for managing your WCF communication channels.

Please download and go over the presentation slides I composed to get a proper overview.
WcfContrib Client Realm.pptx
WcfContrib Client Channel Extensions.pptx


  • Different management options - control the way the communication channels are handled
  • Simple Invocations - invocations made simple, read below.
  • Optimizations - caching of the channel factory, employing best practices
  • Extensions Framework - A framework resembles WCF allowing you to extend and plug into the Client Channel infrastructure
    • Please go over the presentation slides regarding the client channel extensions
  • Error Handling - Subscribe to events to catch all invocation exceptions or derive and override OnInvokeException to apply any logic.
  • Using Using - Using a using block with the client channel is considered safe (unlike WCF communication channel). It automatically aborts if the channel is faulted instead of calling close.
  • Output Caching - Useful feature, read about it on the ClientChannelOutputCache page.

Channel Management Options

Each client channel has a management options which dictate how to handle the WCF communication channels within.
You can provide your own preferred set of management options when you instantiate a new client channel.
The available options are: (Note it's an enum marked as Flags so you can mix and match) Combination Set Options
There are available option sets you can choose from.
  • Single Call
    • Channel Per Call & Close Async after one-way
    • The default behavior for the singleton instance property
  • Sequential
    • Close Async after one-way & Renew faulted channel
  • Sequential Async Own Channel
    • Sequential & Async Own Channel

Usage Guideline
Essentially, you should use it as follows:
  • None - for cases where you want full control, such as session-aware services
  • Sequential / SequentialAsyncOwnChannel - call several operations on a service one after another
  • SingleCall - call a single service operation
Read more - WCF – How to use client channel proxies

Service Invocations

WCF proxies proper usage causes a lot of code and plumbing that gets repetitive.
A single operation invocation would be as follows:

   public static void Main()
      string result = CallService();

   public static string CallService()
      MyServiceClient c = new MyServiceClient();
           string result = c.GetStringFromService();
           return result;

This is exactly the same:
   public static void Main()
      string result = ClientChannel<IMyService>.Instance.Channel.CallService();

That's it, no other code is needed.
Note: Unless you work with a client channel instantiated with "None" as the management option - then it is still up to you to close / abort as needed. (Resembles the code above)
Please make sure you read the section about the management options.

Asynchronous Invocations

The client channel encapsulates asynchronous operation invocations to make it simpler for you to call these.
It calls your asynchronous callback only when completed and provides you with either the result or the error.
  • No need to worry about exception in the begin or end invocation phases - the callback will be called with the error information.
  • No need to call the End method, does it for you

   public static void Main()
      ClientChannel<IMyService>.Instance.Channel.BeginCallService(new AsyncCallback(OnCallServiceCompleted), null);

   public void OnCallServiceCompleted(IAsyncResult result)
      ChannelInvokeAsyncResult invokeResult = result as ChannelInvokeAsyncResult;

      if (!invokeResult.HasError)
         //Process result here..
         //Handle error

Last edited Feb 9, 2010 at 9:21 AM by zuker, version 12


BrainDrain Nov 14, 2013 at 7:43 AM 
>Asynchronous Invocations
no useful functionality provided like allowing to call service methods asynchronously using only 'sync' interface.