I'm writing a mini-framework to aid with client-server connections using WCF, and I've encountered unexpected behavior.
If a client opens a channel to a service that is not available, and then makes a method call vis-a-vis that service, the resulting behavior differs depending on whether or not the binding for the channel has transferMode set to "Streaming".
If the binding is not set to streaming and the service is unavailable, WCF immediately raises the ICommunicationObject.Faulted event. On the other hand, if it is, WCF raises the ICommunicationObject.Opened event.
Can anyone explain the reason for this difference in behavior? Seems pretty odd.
Well, I've been researching this for several hours and believe that I have an answer (I'll mark this as the answer eventually if no one has a better answer).
According to this article on msdn, "All streaming calls are made through a single channel (the datagram channel) that does not support sessions even if the binding being used is configured to use sessions." (Note the bolded text.) Although it's not so clear to me what it means to be using a datagram channel over a TCP/IP protocol, I'll take it at face-value.
So, another msdn article, states that "A datagram channel is a channel in which all messages are uncorrelated. With a datagram channel, if an input or output operation fails, the next operation is typically unaffected, and the same channel can be reused. Because of this, datagram channels typically do not fault."
So, apparently, streaming channels simply do not fault. Although trying to send a message over the channel throws a socket exception (because if the service is unavailable obviously the socket cannot be opened), as far as WCF is concerned, this does not mean that the state of the channel is faulted. I.e., you can still send another message over the same channel and, if the service becomes available, the message might transfer successfully.
It still seems odd to me though, that a channel's state is considered to be open when the socket connection was never made. So I'd still be glad to hear an explanation if someone has a deeper understanding of this.