WCF Communication Objects states Cheat Sheet
WCF is all about communication objects – channels, listeners, factories, all implement the ICommunicationObject interface (some through the CommunicationObject class). This provides a base implementation for the basic state machine states and transitions common to all communication-oriented object.
At any given point in time, the communication objects find themselves in a CommunicationState. Here is a diagram with the states and the transitions:
When we look at a communication object in a debugger, we see something like this (some columns and internal objects removed for brevity reasons):
Name: System.ServiceModel.Channels.ServiceChannel
Fields:
Type | VT | Value | Name |
System.Boolean | 1 | 0 | aborted |
System.Boolean | 1 | 0 | closeCalled |
System.Boolean | 1 | 0 | onClosingCalled |
System.Boolean | 1 | 0 | onClosedCalled |
System.Boolean | 1 | 1 | onOpeningCalled |
System.Boolean | 1 | 1 | onOpenedCalled |
System.Boolean | 1 | 0 | raisedClosed |
System.Boolean | 1 | 0 | raisedClosing |
System.Boolean | 1 | 0 | raisedFaulted |
System.Boolean | 1 | 0 | traceOpenAndClose |
System.Object | 0 | 000000000131d8e0 | eventSender |
System.Int32 | 1 | 2 | state |
System.EventHandler | 0 | 0 | Closed |
System.EventHandler | 0 | 0 | Closing |
System.EventHandler | 0 | 0 | Faulted |
System.EventHandler | 0 | 0 | Opened |
System.EventHandler | 0 | 0 | Opening |
In our example, the communication object is in state 2. How does that translate to the actual states? To tell you the truth, I always take some time to map the number to the state, so I started using this cheat sheet:
public enum CommunicationState
{
Created = 0,
Opening = 1,
Opened = 2,
Closing = 3,
Closed = 4,
Faulted = 5
}
So in our case, the ServiceChannel is Opened. We could identify the state by looking at the other variable – if close called or aborted was called, we can only by in state 4 or 5 and so on. But the cheat sheet makes it simple.
Hope you find it useful!
Comments
- Anonymous
May 30, 2010
Didnt i say communication objects like for an examplet.v, internet, texting, sonar noise and all that.