Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF 4 Soap and Json Endpoint Secured with DotNetOpenAuth

I have a WCF 4 service project that I created using the WCF REST Service Template 40.

My goal is to expose a single WCF service out as both a SOAP endpoint and a RESTful endpoint that returns JSON formatted data. Both endpoints must be protected via my DotNetOpenAuth OAuthAuthorizationManager that is copied from the sample project.

Thusfar, I have a SOAP WCF services that can successfully authorize a consumer from my OAuth service provider. To do this I used the same config that was in the DotNetOpenAuth Service Provider example.

Now, I am trying to setup a WCF RESTful JSON response endpoint for the same service and also secure that endpoint. I am unsure how to accomplish this. My initial idea was to make it look like this:

<behaviors>
  <serviceBehaviors>
    <behavior name="DataApiBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
      <serviceAuthorization principalPermissionMode="Custom" serviceAuthorizationManagerType="OAuthServiceProvider.Core.OAuthAuthorizationManager, OAuthServiceProvider" />
    </behavior>
    <behavior name="">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>

<services>
  <service behaviorConfiguration="DataApiBehavior" name="OAuthServices.DataApi">
    <endpoint address="soap" binding="wsHttpBinding" contract="OAuthServices.Interfaces.IDataApi"/>
    <endpoint address="json" binding="webHttpBinding" contract="OAuthServices.Interfaces.IDataApi"/>
  </service>
</services>

And then I saw this blog post about making RESTful WCF services + DotNetOpenAuth work together: http://www.theleagueofpaul.com/codesnippet-ooo-openid-odata-oauth-together

I am not sure if setting up a Factory plus the ServiceAuthorization section of the service config would cause problems.

I am also unsure if there is anything I need to do in the RegisterRoutes method in the Global.asax:

private void RegisterRoutes()
{
    RouteTable.Routes.Add(new ServiceRoute("DataApi", new WebServiceHostFactory(), typeof(DataApi)));
}

Any advice here would be appreciated. Thanks for any assistance.

Please let me know if you need more information.

like image 238
Brandon Avatar asked Apr 04 '11 21:04

Brandon


1 Answers

Not sure, but I've heard that to enable SOAP you need to use basicHttpBinding and set

aspNetCompatibilityEnabled="true"

I could be wrong, but why not try?

like image 96
Mariusz Avatar answered Sep 27 '22 23:09

Mariusz