Invoke/Reflection vs direct cast to service type?

Jun 28, 2009 at 7:04 PM
Edited Jun 29, 2009 at 4:51 AM


I was wondering if you could explain why you chose to use invoke/refection pattern as opposed to direct cast to service type?  It is not clear why it is not possible to cast the InnerChannel to the service type,

public string CreateItem(TodoList.WpfClient.ServiceReference1.TodoItem( item) {
    return base.Invoke<string>("CreateItem", item);


public string CreateItem(TodoList.WpfClient.ServiceReference1.TodoItem( item) {
    ITodoListService service = (ITodoListService) this.InnerChannel;
    return service.CreateItem(item);

There must be a reason, it is just not obvious to me.

Jun 29, 2009 at 9:20 AM

I'm calling the base class Invoke() which does all the proxy recreation magic and retries.

Jun 29, 2009 at 4:03 PM

Ok, I see that now.  Retry happens when a CommunicationException is thrown. I would assume CommunicationException is a 'fail fast' type exception.  I have this old condition called Reflection-phobia. I guess it has been drilled into me to avoid reflection for performance reasons. However, in this case, the cost of reflection relative to the cost of going out over the wire is insignificant.

Any chance you have plans on releasing the source code for the add-in ?

Jun 29, 2009 at 4:11 PM

I will post the add-in source this summer (as soon as I can) after I get the installation to properly handle modifying registry entries.

Jul 1, 2009 at 4:06 AM


Just post the code, and you never know, one of the people out there might even get it working for you ;)  That's the beauty of Open Source, you shouldn't have to do it all yourself.  You don't have to give them commit access, they can send you the fix and you can approve it, and post it ;)