8. HttpRequestMessage
• In System.Net.Http namespace
• Properties:
o Content – HttpContent
o Headers – HttpRequestHeaders
o Method – HttpMethod
o Properties – IDictionary<string, object>
o RequestUri – Uri
9. Request Extensions
• CreateErrorResponse – many overloads
• CreateResponse – many overloads
• GetClientCertificate
• GetProperty<T>
• GetQueryNameValuePairs
• GetUrlHelper
These are in System.Net.Http.dll.
11. HttpResponseMessage
• In System.Net.Http namespace
• Properties:
o Content – HttpContent
o Headers – HttpResponseHeaders
o IsSuccessStatusCode – bool
o ReasonString – string
o RequestMessage – HttpRequestMessage
o StatusCode – HttpStatusCode
12. Key Attributes
o HttpGet
o HttpPost
o HttpPut
o HttpPatch
o HttpDelete
o HttpHead
o HttpOptions
o AcceptVerbs
o Authorize
o AllowAnonymous
o NonAction
o FromBody
o FromUri
o Queryable
13. Example One
Create a Simple Controller to Fetch Person Entities
Add OData Query Syntax Support
14. Example One Summary
• Implement a basic controller with a actions
• Demonstrate controller selection by convention
• Discuss controller selection by attribution
• Implement OData query parameters and
demonstrate
20. Example Three Summary
• Implement an application key handler
• Discuss the invocation of the InnerHandler
• Demonstrate the creation and return of an error
response
• Discuss why throwing exceptions will always return
an HTTP 500 (Internal Server Error) result
• Demonstrate using the request object to create the
error response instead
• Attach the handler to the pipeline
• Debug with Help & Test
21. Possible Uses
• Implementing a cache manager
• Implementing an AAA scheme
• Capturing pay-per-call data
• Recording statistics
• Logging and tracing
• Inserting custom request and response headers
• Performing message compression or encryption
• Transforming messages
22. Testing Web API
• Faking context with ASMX and WCF is difficult
• Too many platform dependencies
o ASP.NET produces an HttpContext
o WFC produces an OperationContext
• Typically requires a running host