Welcome to MSDN Blogs Sign in | Join | Help

Just the Headers

How do I change the HTTP status code of the response that is sent back when using a one-way contract?

The result of using a one-way contract is to automatically send back an empty HTTP response when the service method is called. Sending back this response is independent of executing your service code. This means that the normal method of attaching a message property to set the HTTP status code and other HTTP headers can't be applied. There is no reply channel waiting for you to set up a message with the appropriate properties.

However, there is another mechanism for sending back an empty HTTP response where you do have control over the HTTP headers. When you're using the standard request-reply contract with HTTP, you can manipulate the HTTP message that gets sent back for the reply. On that message you can put an HttpResponseMessageProperty that has SuppressEntityBody set to true. SuppressEntityBody produces equivalent messages to a one-way contract that have HTTP headers but no body contents.

You should think of one-way messages and empty messages as having the same appearance but different semantics during processing. The other way around the problem is to find a lower processing layer to apply your HTTP headers. If you get below the processing layer that knows about one-way messaging, then one-way messages and empty messages are not distinguishable. It is the processing layer that recognizes the one-way protocol that creates the distinction.

Next time: Binary Encodings and Addressing

Published Thursday, May 31, 2007 5:00 AM by Nicholas Allen
Filed under: , , ,

Comments

Thursday, May 31, 2007 9:10 AM by Alan Dean

# re: Just the Headers

"On that message you can put an HttpResponseMessageProperty that has SuppressEntityBody set to true. SuppressEntityBody produces equivalent messages to a one-way contract that have HTTP headers but no body contents."

aka: a HEAD request, rather than a GET

http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.4

Thursday, May 31, 2007 1:01 PM by Nicholas Allen's Indigo Blog

# Close Your Proxies

Hey! Call Close on your client proxy objects once you're done using them! This is always a good idea,

Thursday, May 31, 2007 2:55 PM by Nicholas Allen

# re: Just the Headers

The HTTP verb isn't really significant here because the client gets to pick the verb (could be anything) whereas the server is the one deciding not to send a body with the response.  A lot of SOAP processing is done with POST instead of GET so switching to one-way doesn't affect that.

Thursday, May 31, 2007 3:32 PM by Jason Haley

# Interesting Finds: May 31, 2007

Friday, June 01, 2007 5:20 PM by Juan Wajnerman

# re: Just the Headers

I think (if I understand well your approach) that you will loose the "fire-and-forget" behavior of one way operations. Am I correct?

Unless there is a way to return the empty message and continue with the execution flow somewhere in WCF stack. Is it possible?

Friday, June 01, 2007 11:00 PM by Nicholas Allen

# re: Just the Headers

Juan-

That's correct.  By pushing the message processing up the stack, you lose the fire and forget behavior.  There is a way though to send back an empty message but still continue on with execution.  That way does require writing a channel.  We have written such a OneWay channel- http://blogs.msdn.com/drnick/archive/2006/08/16/702174.aspx.  The extensibility exists in the product for someone to write a similar channel or to modify the output of our OneWay channel to meet their needs.

New Comments to this post are disabled
 
Page view tracker