O'Reilly logo

RESTful .NET by Jon Flanders

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 11. Working with HTTP

One of the benefits of programming in the world of REST is the ability to take advantage of the maturity of HTTP and the established infrastructure of the Web. To do this successfully in a programming environment, you need access to the underlying HTTP constructs so that you can modify HTTP headers programmatically and take full advantage of this rich platform.

In this chapter, you will learn how WCF exposes the world of HTTP through its programming model, along with the most common ways you’ll likely end up interacting with HTTP.

Programming HTTP with WCF

I introduced the WCF HTTP programming model in Chapter 2. Whenever you are using HTTP with WCF, you can ask for the current WebOperationContext object through the WebOperationContext.Current static property. The first time you ask for this property, a new instance of the WebOperationContext object is created and attached to the current WCF generic OperationContext object. On subsequent property accesses, of course, the already-created instance is returned.

Note

I should reiterate that WCF automatically modifies the HTTP requests and responses based on the ServiceContract definition. An operation’s WebGetAttribute or WebInvokeAttribute tell WCF a lot about what to do with HTTP requests and responses. The URI and the HTTP method are completely influenced by that mechanism.

The HTTP context I will discuss in this chapter illustrates how to go beyond that base functionality.

WebOperationContext is the WCF wrapper ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required