ExceptionHandlingDuplexProxyBase

Jul 20, 2009 at 12:05 PM
Edited Jul 20, 2009 at 2:03 PM

Hi,

I created a solution in order to play around with the "ExceptionHandlingDuplexProxyBase" class.
I noted a few issues that crept up on me while trying to use it, I thought I should surface them here:

1. The private field "IsOpened" should probably be set to true in the eventhandler "InnerChannel_Opened(...)", instead of inside the "Open(..)" methods. Why? Because like me I was listening on the .Opened event, after which I always want to invoke a method on the server (like a Register/Subscribe method). This was impossible since "IsOpened" was still false, when calling this eventhandler, and therefore the proxy would refuse to invoke any methods on the server. So I just moved that "IsOpened = true;" statement to the "InnerChannel_Opened(...)" method instead before calling any listeners on the "Opened" event.

2. I found it very useful to also expose two virtual methods "OnOpened" and "OnClosing" on the ExceptionHandlingDuplexProxyBase, just because I was doing a Register/Unregister (i.e Subscribe/Unsubscribe) pattern always from the clients side, I would guess that this isn't a totally uncommon pattern.

3. The "IsOpen" field is never set to false when the innerchannel faults or closes, hence it was impossible on the client side to issue a "Close" on the Proxy, followed by a later "Open" call, because the proxy would check the "IsOpen" field  and find it set as "True", and therefore refuse to go on and Open.

4. Any reason why you choose not to expose the "IsOpen" as a public Property? Just curious.

5. I had an exceptions occur on me in the proxy class during a call to "o.Abort()" in the "Abort()" method. I guess it (o.Abort();) should probably be encapsulated in an empty try/catch clause. :)

6. Since I'm not totally up to speed with WCF. I wanted to always apply a behavior to the channel factory in my scenario. (A behavior that will always append a client id, in all messages sent to the server). I ended up modifying the ExceptionHandlingDuplexProxyBase class and added a virtual OnChannelFactoryCreated(DuplexChannelFactory<T> channelFactory), which I could take advantage of in my derived class and just apply my behavior. Is there any other better way I could have done that maybe?

7. It might be a good idea to cache the methods on the the first call to the proxy's GetMethod, as to reduce the subsequent calls to mere lookups in the hashtable? Just thinking out aloud here.. :)

Anyway, just some thoughts. Other than that, I find it a VERY useful class, and a very good pattern, with the trying of invoking the command twice before rethrowing the exception, and auto-reconnecting. Smart! Thanks for sharing your code and knowledge with this guidance!

Cheers,
Ted