Inside of IDisposable.Dispose()
method I launch ICommunicationObject.Close()
method of my channel. Is it allowed to call ICommunicationObject.Close()
when the CommunicationState
of the channel is CommunicationState.Opening
?
I.e. is such checking sufficient for the ICommunicationObject
instance closing?
ICommunicationObject commObj = channel as ICommunicationObject;
if (null != commObj &&
commObj.State == CommunicationState.Opened ||
commObj.State == CommunicationState.Opening) {
commObj.Close();
}
I believe you can simply check commObj.State != CommunicationState.Closed
.
I've been running a variant of A smarter WCF service client without issue for years.