Check status of the ChannelFactory channel

时间:2018-07-16 15:26:32

标签: c# channelfactory

in my project I need to check if channell is in faulted state before initialize communication on it but I'm getting a cast exception doing it like this:

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
            ///....
        }
  }
}

0 个答案:

没有答案