2012-04-10 111 views
1

嗨,ICommunicationObject.State不起作用?

创建我有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(); 

回答

3

铸成IClientChannel,然后检查国家

但是,当你拨打电话要小心,国家才会更新。如果您想测试通道没有超时,那么您不可能发出引发异常的呼叫。

+3

使用IClentChannel时,我会得到完全相同的异常吗? – Banshee 2012-04-10 11:28:29

+0

您可以添加'GetMyServiceInterfaceChannel'创建代码吗? – Fabske 2012-04-10 11:31:36

+0

看看我的编辑。 – Banshee 2012-04-10 11:42:49