Partager via


Mixed Mode Addressing

WCF has a variety of addressing controls for specifying where messages should be sent. For example, there's the To address of the logical endpoint, the Via address of the physical endpoint, the ReplyTo address of the endpoint where the response should go, and so on. In most simple cases, it's not necessary to actually specify all of these addresses. There's a single party to the conversation to which you send all of your messages. And, that other party knows that it should send all of its messages to you regardless of whether those messages are replies, faults, or acknowledgments. There are three addressing patterns that capture these kinds of relationships.

Anonymous addresses are the simplest form of addressing. Anonymous addressing is used when there is an inherent logical path for a response. TCP is a bidirectional communication transport. Where should I send a response to a TCP message? Well, a good guess is back to whoever is on the other side of the socket that sent me the message in the first place. I don't have to think about what that person is called. Similarly, the request-reply model of HTTP means that there's always an obvious destination for responses. You have one chance to use the HTTP reply channel and using it also doesn't require you to know where the messages are going.

Directed addresses cover the case where sending the response requires creating a new channel for communication. With dual HTTP, the client creates one HTTP request to send a message and then the server needs to create its own HTTP request to send a response. Since the server is initiating the send, it needs a specific endpoint to establish a connection. You have to give the server the address of some endpoint for the response. One-way messaging also requires directed addressing because there's no back channel for communication. If the server wants to send a message back, that's a completely separate operation from the first message as far as anyone's concerned.

WCF supports either anonymous or direct modes of address for any particular binding. The common TCP and HTTP bindings always use anonymous addresses and the less common dual HTTP binding always uses directed addresses. However, there is a third form of addressing that sometimes uses anonymous addresses and sometimes uses directed addresses. Mixed-mode addressing combines anonymous and directed addresses depending on the message that is being sent. A typical example of mixed-mode addressing is the use of a dedicate machine for processing fault or acknowledgment messages. If the standard exchange sequence for replies is HTTP or TCP, the responses use anonymous addressing but the faults use directed addressing. Using mixed-mode addressing requires a lot of fiddling at the level of channels because it does not compose nicely with the service-oriented view of messaging.

Next time: Pull Not Push

Comments

  • Anonymous
    November 02, 2006
    Windows Vista The big news, according to News.com , Steve Ballmer will ring in availability of Windows

  • Anonymous
    November 02, 2006
    This is just a style convention that helps you avoid doing some thinking while writing custom channel

  • Anonymous
    November 04, 2006
    Great article, Nicholas! Is there any code sample for message addressing. What's going on if we don't know the receiver service of the message. Can we set dynamic the 'To' property?

  • Anonymous
    November 12, 2006
    Rado also sent me email related to this question.  There are two resources that help explain what to do: The MessageHeaders class (http://msdn2.microsoft.com/en-us/library/system.servicemodel.channels.messageheaders.aspx) is the API through which these headers are set. The REST and POX sample (http://msdn2.microsoft.com/en-us/library/aa395208.aspx) gives a specific example of dynamically selecting the destination address per-message.

  • Anonymous
    February 19, 2007
    I haven't forgotten about the goal to put together a table of contents for all of these articles. The