ICommunicationObject.State do not work?

2.6k views Asked by At

Hi,

I create my WCF client with DuplexChannelFactory, the problem is that when I do this :

((ICommunicationObject)this.GetMyServiceInterfaceChannel).State

I get the followin exception :

Cannot obtain fields or call methods on the instance of type 'System.ServiceModel.ICommunicationObject' because it is a proxy to a remote object.

Why?

I need to check if the channel is faulted.

Edit1:

ClientService clientService = new ClientService();
                InstanceContext context = new InstanceContext(clientService);

                DuplexChannelFactory<My.ServiceContracts.IMyClientService> factory = new DuplexChannelFactory<My.ServiceContracts.IMyClientService>(context, connectionName);

                factory.Credentials.UserName.UserName = anvandarNamn;
                factory.Credentials.UserName.Password = password;


                return factory.CreateChannel();
1

There are 1 answers

3
Fabske On BEST ANSWER

Cast as IClientChannel, then check the State

But be carefull that the State is only updated when you make a call. If you want to test that the channel doesn't timeout, it's not possible untill you make a call that throw the exception.