Integrating DotNetOpenAuth and WCF WebAPI

Topics: Web Api
Aug 5, 2011 at 8:19 AM
Edited Aug 5, 2011 at 8:21 AM

(this is a crosspost from Stackoverflow - http://goo.gl/NwCxY - where somebody suggested to try the same question here)

I am trying to create a RESTful web service based on WCF Web API. I also need to control access using OAuth and for this I am using the DotNetOpenAuth open source library.

Has anyone ever been successful integrating the two? I am struggling converting from the HTTP entities representations of the WCF Web API into something that's understandable by DNOA (e.g. HTTP requests, HTTP headers, etc...).

Any tip would be greatly appreciated.

  Stefano

Aug 7, 2011 at 11:13 PM

Could you be a little more specific?

In Web API a request is represented by the HttpRequestMessage class (http://wcf.codeplex.com/SourceControl/changeset/view/417c9a96fc24#WCFWebApi%2fHttp%2fSrc%2fMicrosoft.Net.Http%2fHttpRequestMessage.cs).

A response is represented by the HttpResponseMessage class (http://wcf.codeplex.com/SourceControl/changeset/view/417c9a96fc24#WCFWebApi%2fHttp%2fSrc%2fMicrosoft.Net.Http%2fHttpResponseMessage.cs).

I've no previous knowledge of DNOA, but from what I saw, you can easily create a HttpRequestInfo from a HttpRequestMessage using the public HttpRequestInfo(string httpMethod, Uri requestUrl, string rawUrl, WebHeaderCollection headers, Stream inputStream)

  • The HTTP method and request uri are directly HttpRequestMessage properties.
  • The input stream is obtained via the Content property.
  • I don't see a direct way of creating a WebHeaderCollection from the Web API's HttpRequestHeaders. However, you can iterate the HttpRequestHeaders entries and insert then on the WebHeaderCollection one by one.

HTH

Pedro

Aug 8, 2011 at 8:10 AM

Pedro,

I eventually followed the very same path that you mentioned, so your comment reinforces my intuition.

Thank you,

 Stefano.