【问题标题】:Using ASP.NET Membership Provider authentincation in a WCF service在 WCF 服务中使用 ASP.NET 成员资格提供程序身份验证
【发布时间】:2011-02-06 14:28:39
【问题描述】:

有没有办法使用会员提供者提供的相同用户名和密码进行 WCF 服务身份验证?如果是这样,它支持哪种绑定?我需要从当前调用服务的用户中提取配置文件变量。感谢您的帮助。

【问题讨论】:

    标签: asp.net wcf asp.net-membership wcf-security


    【解决方案1】:

    基本上,任何接受用户名/密码作为消息安全客户端凭据的绑定都可以配置为使用 ASP.NET 成员资格提供程序。

    查看how to use the ASP.NET Membership provider in WCF 上的此 MSDN 文档 - 您需要为“用户名”类型的客户端凭据配置绑定

    <bindings>
      <wsHttpBinding>
      <!-- Set up a binding that uses UserName as the client credential type -->
        <binding name="MembershipBinding">
          <security mode ="Message">
            <message clientCredentialType ="UserName"/>
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    

    以及使用 ASP.NET Membership 进行用户身份验证的服务:

    <serviceBehaviors>
      <behavior name="AspNetMembership">
         <serviceCredentials>
            <userNameAuthentication 
                 userNamePasswordValidationMode ="MembershipProvider" 
                 membershipProviderName ="SqlMembershipProvider"/>
         </serviceCredentials>
      </behavior>
    </serviceBehaviors>
    

    当然,您必须在配置服务时将此服务行为应用于您的服务!

    <services>
       <service name="YourService" behaviorConfiguration="AspNetMembership">
       ....
       </service>
    </services>
    

    basicHttpBinding、wsHttpBinding、netTcpBinding 支持 UserName 客户端凭据类型 - 几乎所有常见的嫌疑人。

    【讨论】:

    • 是否可以在不使用 https 的情况下将用户名与 basicHttpBinding 一起使用?另外,如果我使用 wsHttpBinding,https 是强制性的吗?
    • 如果您使用用户名/密码,WCF 需要一个安全链接 - 所以您必须使用 https(因为您不能使用基于消息的加密)。不:您绝对可以在没有 https 的情况下使用 wsHttpBinding - 只要您可以加密消息,例如通过提供可用的证书
    猜你喜欢
    • 1970-01-01
    • 2011-03-27
    • 2011-05-01
    • 2011-04-13
    • 2012-02-11
    • 2011-07-25
    • 2012-07-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多