ICommunicationObject.State do not work?

假装没事ソ 提交于 2019-12-13 01:28:24

问题


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:


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.



来源:https://stackoverflow.com/questions/10085779/icommunicationobject-state-do-not-work

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!