2012-04-10 22 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