MiaoMiao M

MiaoMiao M

  • 0
  • 7
  • 4.8k

Question about using delegate Action and Generics when calling WCF service

May 6 2011 1:21 PM

Hi all. I just started to learn how to use WCF. I encouter the compiling errors when tring to use System.Action to call the WCF service. Here is the code that calls the generic function:

In UserServiceProxy.cs:

new ClientFactory().TryExecuteAndClose(delegate(UserServiceClient client)


UserEntity entity=client.GetCurrentUser(true)


Then in ClientFactoryBase.cs, I have:

public void TryExecuteAndClose<Client> (Action<Client> action, string bindingType) where Client: ICommunicationObject, new()


var client=default(UserServiceClient);




client=new UserServiceClient("basic");


client = new UserServiceClient("secure");


action(client); //##############this is where I got compile error.



The 2 errors that I got are complaining about "delegate System.Action<Client> has some invalid arguments" and "Cann't convert UserServiceWcf.UserServiceClient to Client".

Could someone help me on how to fix the errors? Thanks a lot.

Brought to you by:

Answers (5)