在WCF服务中使用ASP.NET Membership Provider身份验证

17

是否有一种方法可以在WCF服务身份验证中使用与会员提供程序相同的用户名和密码?如果是,它支持哪种绑定?我需要从当前调用服务的用户中提取一个配置文件变量。感谢任何帮助。

1个回答

22
基本上,任何接受用户名/密码作为客户端凭据的消息安全绑定都可以配置为使用ASP.NET成员身份验证提供程序。
请查看这个MSDN文档,了解如何在WCF中使用ASP.NET成员身份验证提供程序 - 你需要为用户名类型的客户端凭据配置你的绑定。
<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>

UserName客户端凭据类型受basicHttpBinding、wsHttpBinding和netTcpBinding支持,因此基本上所有常见的绑定都支持。


使用basicHttpBinding时,是否可以不使用https来与用户名进行身份验证?另外,如果我使用wsHttpBinding,是否必须使用https? - Nil Pun
2
如果您正在使用用户名/密码,WCF需要一个安全链接 - 因此您必须使用https(因为您无法使用基于消息的加密)。但是不,您绝对可以在没有https的情况下使用wsHttpBinding - 只要您可以加密消息,例如通过拥有可用证书。 - marc_s
你能否回答一下这个问题:http://stackoverflow.com/questions/9584198/authentication-service-using-wcf? - LCJ

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接