ICommunicationObject.State不起作用?

时间:2012-04-10 08:58:30

标签: c# .net wcf faulted

您好,

我使用DuplexChannelFactory创建我的WCF客户端,问题是当我这样做时:

((ICommunicationObject)this.GetMyServiceInterfaceChannel).State

我得到了以下例外:

无法在类型为“System.ServiceModel.ICommunicationObject”的实例上获取字段或调用方法,因为它是远程对象的代理。

为什么?

我需要检查频道是否出现故障。

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 个答案:

答案 0 :(得分:4)

投射为IClientChannel,然后检查状态

但请注意,只有在您拨打电话时才会更新状态。如果你想测试通道没有超时,那么你就不可能进行一次抛出异常的调用。