C# 检查通道工厂通道的状态
在我的项目中,在初始化channell上的通信之前,我需要检查它是否处于故障状态,但我得到一个强制转换异常,如下所示:C# 检查通道工厂通道的状态,c#,channelfactory,C#,Channelfactory,在我的项目中,在初始化channell上的通信之前,我需要检查它是否处于故障状态,但我得到一个强制转换异常,如下所示: public class myClass : myInterface { private myInterface _service; public myClass() { ///service initialization //...../// this._service = new ChannelFactory<myInterface>
public class myClass : myInterface
{
private myInterface _service;
public myClass()
{
///service initialization
//.....///
this._service = new ChannelFactory<myInterface>(binding, remoteAddress).CreateChannel();
}
public void login()
{
//This is where i get cast exception
if ((**(ChannelFactory<myInterface>)_service).State** == System.ServiceModel.CommunicationState.Faulted)
{
// re-initialize service
///....
}
}
}
公共类myClass:myInterface
{
私有myInterface\u服务;
公共myClass()
{
///服务初始化
//.....///
此._service=newchannelfactory(绑定,远程地址).CreateChannel();
}
公共无效登录()
{
//这就是我得到cast异常的地方
if((**(ChannelFactory)u service.State**==System.ServiceModel.CommunicationState.Faulted)
{
//重新初始化服务
///....
}
}
}
尝试将\u服务
转换为ICommunicationObject
这很有效,谢谢!