【问题标题】:User authentication based on basicHttpBinding without certificate基于basicHttpBinding的用户认证,无需证书
【发布时间】:2013-10-31 20:55:30
【问题描述】:

我正在尝试设置一个 Web 服务,该服务具有用户名和密码才能访问该服务。我使用这个链接作为指导http://www.codeproject.com/Articles/642997/Generate-username-authentication-based-on-basicHtt

我遇到了无法绕过以下错误的区域。使用下面的配置,我收到了此错误消息

主机上配置的身份验证方案('Anonymous')不允许在绑定'BasicHttpBinding'('Basic')上配置的身份验证方案。请确保将 SecurityMode 设置为 Transport 或 TransportCredentialOnly。此外,可以通过 IIS 管理工具、通过 ServiceHost.Authentication.AuthenticationSchemes 属性、在元素的应用程序配置文件中更改此应用程序的身份验证方案、通过更新绑定上的 ClientCredentialType 属性或通过调整来解决此问题HttpTransportBindingElement 上的 AuthenticationScheme 属性。

我的配置文件是

<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
<system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior name="customBehavior">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
      <serviceCredentials>
        <userNameAuthentication
          userNamePasswordValidationMode="Custom"
          customUserNamePasswordValidatorType="Project.Services.MyService, Project.Services"/>
      </serviceCredentials>
    </behavior>
  </serviceBehaviors>
</behaviors>
<bindings>
  <basicHttpBinding>
    <binding name="MyBasicHttpBinding">
      <security mode="Transport">
        <transport clientCredentialType="Basic" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
<services>
  <service behaviorConfiguration="customBehavior" name="Project.Services.MyService">
    <endpoint address=""
      binding="basicHttpBinding" bindingConfiguration="MyBasicHttpBinding"
      contract="Project.Services.Interfaces.ITechnology">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost/Service/myService.svc" />
      </baseAddresses>
    </host>
  </service>
</services>
  </system.serviceModel>
  <appSettings>
    <add key="userName" value="user1"/>
    <add key="password" value="password"/>
  </appSettings>
</configuration>

wcf 服务将与 Windows Phone 8 应用程序一起使用。我已经阅读了几篇关于该错误的文章,并将端点地址设置为“”,但我所做的一切都没有奏效。我不得不回到上面的配置,因为我认为我做了太多的改变,这可能会让我走错路。

该服务托管在我的本地 IIS 上(Win 8 64 位专业版 + 所有更新)。

有人可以帮忙吗?

【问题讨论】:

  • 在 WCF 中使用带有用户名身份验证的 BasicHttpBinding 时的基本规则是,您不能通过 http 传递用户名/密码,因为 http 传输是明文。因此,您必须启用使其成为 https 的传输安全性。
  • 虽然我同意您的评论,但我最初遇到的问题是 Windows Phone 8 不支持 https 用户名身份验证 - 这就是为什么我必须使用带有用户/密码的 basicHttpBinding。让我知道这是否不正确

标签: wcf windows-phone-8 wcf-binding wcf-security


【解决方案1】:

根据错误,您需要设置 IIS 以在您的服务上允许“基本身份验证”。

在 IIS 管理控制台中,选择身份验证选项卡并设置允许“基本身份验证”。另外,禁用“匿名身份验证”。

如果“基本身份验证”不存在,您需要将此角色添加到您的 IIS。 检查如何做到这一点here

【讨论】:

  • 谢谢米格尔。我已经更改了我的配置文件(请参阅原始帖子)。当我通过浏览器连接到服务时,我会提示输入用户名和密码,但输入 user1/password 不会让我进入服务页面。然而,允许匿名身份验证确实违背了我试图实现的目标。这是什么原因?
  • 可能尝试直接在 IIS 上使用本地用户,而不是使用服务验证可以让您查看错误是在配置上还是在代码上。为此,请授予用户对部署服务的文件夹的读取权限。
  • 我会试一试。那么我需要文件中的用户/密码配置吗?最后我需要实现 System.IdentityModel.Selectors.UserNamePasswordValidator
  • 不,不需要。 IIS 使用 windows 进行身份验证。不要忘记在您的配置中删除您的 serviceCredencials
猜你喜欢
  • 2013-10-16
  • 2023-03-22
  • 1970-01-01
  • 1970-01-01
  • 2015-09-06
  • 1970-01-01
  • 1970-01-01
  • 2021-09-21
  • 2010-11-30
相关资源
最近更新 更多