1

你好,

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

((ICommunicationObject)this.GetMyServiceInterfaceChannel).State

我得到以下异常:

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

为什么?

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

编辑1:

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();
4

1 回答 1

4

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.

于 2012-04-10T09:02:13.560 回答