【问题标题】:WCF 4 Soap and Json Endpoint Secured with DotNetOpenAuth使用 DotNetOpenAuth 保护 WCF 4 Soap 和 Json 端点
【发布时间】:2011-04-04 21:22:40
【问题描述】:

我有一个使用 WCF REST 服务模板 40 创建的 WCF 4 服务项目。

我的目标是将单个 WCF 服务公开为 SOAP 端点和返回 JSON 格式数据的 RESTful 端点。两个端点都必须通过我从示例项目中复制的 DotNetOpenAuth OAuthAuthorizationManager 进行保护。

到目前为止,我有一个 SOAP WCF 服务,它可以成功地从我的 OAuth 服务提供者那里授权消费者。为此,我使用了与 DotNetOpenAuth 服务提供程序示例中相同的配置。

现在,我正在尝试为同一服务设置 WCF RESTful JSON 响应端点并保护该端点。我不确定如何做到这一点。我最初的想法是让它看起来像这样:

<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>

然后我看到了这篇关于使 RESTful WCF 服务 + DotNetOpenAuth 协同工作的博客文章: http://www.theleagueofpaul.com/codesnippet-ooo-openid-odata-oauth-together

我不确定设置工厂和服务配置的 ServiceAuthorization 部分是否会导致问题。

我也不确定是否需要在 Global.asax 的 RegisterRoutes 方法中做任何事情:

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

如有任何建议,我们将不胜感激。感谢您的帮助。

如果您需要更多信息,请告诉我。

【问题讨论】:

    标签: c# .net wcf rest dotnetopenauth


    【解决方案1】:

    不确定,但我听说要启用 SOAP,您需要使用 basicHttpBinding 并设置

    aspNetCompatibilityEnabled="true"

    我可能错了,但为什么不试试呢?

    【讨论】:

    • 正确!要使 Json 端点正常工作,您需要带有 aspNetCompatibilityEnabled="Tru" 的 BasicHttpBinding
    猜你喜欢
    • 2011-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-20
    相关资源
    最近更新 更多