【问题标题】:How to authenticate client while consuming the WCF web service?如何在使用 WCF Web 服务时对客户端进行身份验证?
【发布时间】:2010-11-15 01:57:03
【问题描述】:

我想在使用 Web 服务时对客户端进行身份验证。我看到客户端中公开了一个名为 ClientCredential 的属性,我们可以在其中传递用户名和密码。如何将此信息传递给我的 WCF Web 服务以及如何验证用户 ID 和密码?

【问题讨论】:

    标签: wcf wcf-security wcf-client


    【解决方案1】:

    如果您想使用带有用户名/密码的 ClientCredential,您需要像这样在客户端 app.config 中进行配置 - 使用传输或消息安全,无论哪个适合您,然后指定

    <system.serviceModel>
        <bindings>
          <basicHttpBinding>
            <binding name="UserNameSecurity">
              <security mode="Message">
                <message clientCredentialType="UserName"/>
              </security>
            </binding>
          </basicHttpBinding>
    

    然后您需要在客户端的端点中使用此绑定配置“UserNameSecurity”:

        <client>
          <endpoint address="http://localhost:8888/MyService"
                    binding="basicHttpBinding" bindingConfiguration="UserNameSecurity"
                    contract="IMyService" />
    

    在服务器端,您需要定义如何对用户进行身份验证 - 使用 Windows(Active Directory 域)或使用 ASP.NET 成员资格提供程序(及其关联的用户数据库):

      <system.serviceModel>
        <behaviors>
          <serviceBehaviors>
            <behavior name="Default">
              <serviceCredentials>
                <userNameAuthentication userNamePasswordValidationMode="MembershipProvider"/>
              </serviceCredentials>
            </behavior>
          </serviceBehaviors>
        </behaviors>
    

    在这种情况下,您的用户名/密码将根据 ASP.NET 成员数据库进行检查。

    如果这一切都在公司内部的 Intranet 上,我宁愿使用集成的 Windows 安全性 - 它更易于设置和使用,并且更可靠和安全。但它只在公司内部、公司防火墙内部有效。

    马克

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-22
      • 2012-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-15
      • 2010-11-19
      相关资源
      最近更新 更多