是否允许在通道的CommunicationState处于CommunicationState.Opening时调用ICommunicationObject.Close()?

Is it allowed to call ICommunicationObject.Close() when the CommunicationState of channel is being in CommunicationState.Opening?

IDisposable.Dispose() 方法中,我启动了我频道的 ICommunicationObject.Close() 方法。频道CommunicationStateCommunicationState.Opening时是否允许调用ICommunicationObject.Close()

即这样的检查是否足以 ICommunicationObject 实例关闭?

ICommunicationObject commObj = channel as ICommunicationObject;
if (null != commObj &&
    commObj.State == CommunicationState.Opened ||
    commObj.State == CommunicationState.Opening) {

    commObj.Close();
}

我相信你可以简单地检查一下 commObj.State != CommunicationState.Closed

多年来,我一直运行 A smarter WCF service client 的变体,没有任何问题。