Share via


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