The ClientBase provides a Channel property that implements the T ServiceContract interface. What is the method that this class uses to implement the interface automatically and is there an example of how to implement this method generally (i.e., for my own classes) ?
-
The [`ChannelFactory
`](http://msdn.microsoft.com/en-us/library/ms734681%28v=vs.110%29.aspx) is your guy. Here is also a nice discussion on [Channel Factory vs Generated Proxy in WCF](http://stackoverflow.com/questions/1698275/wcf-channelfactory-vs-generating-proxy). – Derek W Jan 16 '15 at 03:33
2 Answers
Seeing the Reference Source, it looks like it's using a Channel Factory...
To make a very long dig shorter, consider this - what you're asking for is a dynamic proxy, a class which intercepts method calls and checks them for data. In the case of WCF, it uses the MethodInfo
and associated attributes to send the call as an RPC over whatever protocol and connection has been established.
See RealProxy for a starter in .NET, and also consider that there are a LOT of Proxy Libraries out there.

- 10,458
- 1
- 28
- 40
I don't know exactly how it's implemented.
But it points to a generic problem in programming - you want to dynamically create an object at runtime that implements any given interface.
In the WCF case, this dynamically created object would intercept any call, then look at the attributes on the method and parameters to determine how to serialize this into a SOAP or JSON message.
An implementation of dynamic proxies that I use is Castle DynamicProxy.

- 44,254
- 30
- 139
- 205