共用方式為


It Makes the WWW Go Round, Part 1: IRequestChannel

The final WCF message exchange pattern that I'm going to look at is the request-reply version of two-way communication.  You may be familiar with the request-reply model as the native way to think about HTTP communication.

Request-reply connections can communicate in both directions, but one of the sides is always the understood speaker.  Initially, the client gets to speak by making a request.  Then, the server gets to speak by making a response.  Unless the client asks for something, the server can't send it any data.  And, if the client is in the process of making one request, it can't make another until the first request completes.  There's a correlation between the messages sent between the two sides.

The client side is implemented by the IRequestChannel interface, which if you were paying attention yesterday, looks almost identical to the IOutputChannel interface.  This should not be unexpected if you've been looking at the channel shape pictures included in each of these posts.

 public interface IRequestChannel : IChannel, ICommunicationObject, IDisposable
{
   EndpointAddress RemoteAddress { get; }
   Uri Via { get; }

   IAsyncResult BeginRequest(Message message, AsyncCallback callback, object state);
   IAsyncResult BeginRequest(Message message, TimeSpan timeout, AsyncCallback callback, object state);
   Message EndRequest(IAsyncResult result);
   Message Request(Message message);
   Message Request(Message message, TimeSpan timeout);
}

The key difference between IRequestChannel and IOutputChannel (besides the fact that the methods are named Request instead of Send) is that the Request method both sends a message and returns a message back.  This is the enforcement of the request-reply pattern in action.  We've already paired up your request with the reply to make it look like the two operations occurred as an indivisible whole.  On the client side, this all looks very nice.

Tomorrow, we'll look at the server side where there's still the flavor of IInputChannel, but the request-reply pattern is much more apparent.

Next time: It Makes the WWW Go Round, Part 2: IReplyChannel

Comments

  • Anonymous
    March 15, 2006
    Yesterday, we got a look at the reader side of the one-way communication pattern, which is implemented...
  • Anonymous
    March 20, 2006
    After a short break, let's continue looking at the request-reply message pattern.  In the previous...
  • Anonymous
    March 21, 2006
    The final player in the drama between IRequestChannel and IReplyChannel is the link connecting requests...
  • Anonymous
    April 18, 2006
    During the last few weeks I've been going over various parts of the channel model and giving some commentary...
  • Anonymous
    June 08, 2006
    I've talked about the request-reply message exchange pattern that HTTP uses, but we've never looked at...