Wcf 基于无证书basicHttpBinding的用户认证

Wcf 基于无证书basicHttpBinding的用户认证,wcf,windows-phone-8,wcf-binding,wcf-security,Wcf,Windows Phone 8,Wcf Binding,Wcf Security,我正在尝试设置一个web服务,它要有用户名和密码才能访问该服务。我使用这个链接作为指导 我遇到了一个无法绕过以下错误的区域。使用下面的配置,我收到了此错误消息 主机(“匿名”)上配置的身份验证方案不允许在绑定“BasicHttpBinding”(“Basic”)上配置的身份验证方案。请确保SecurityMode设置为Transport或TransportCredentialOnly。此外,通过IIS管理工具,通过元素的应用程序配置文件中的ServiceHost.authentication.A

我正在尝试设置一个web服务,它要有用户名和密码才能访问该服务。我使用这个链接作为指导

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

主机(“匿名”)上配置的身份验证方案不允许在绑定“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位pro+所有更新)


有人可以帮忙吗?

根据错误,您需要将IIS设置为允许对您的服务进行“基本身份验证”

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

如果没有“基本身份验证”,则需要将此角色添加到IIS中。
检查如何操作。

在使用BasicHttpBinding和用户名身份验证时,WCF中的一个基本规则是,您不能通过http传递用户名/pwd,因为http传输是明文。因此,您必须启用传输安全性,使其成为https。虽然我同意您的评论,但我最初遇到的问题是Windows Phone 8不支持https用户名验证-这就是为什么我必须使用basicHttpBinding和用户/密码。如果这不正确,请告诉我谢谢米格尔。我已经更改了我的配置文件(请参阅原始帖子)。当我通过浏览器连接到服务时,会收到输入用户名和密码的提示,但输入user1/password无法进入服务页面。然而,允许匿名身份验证确实会破坏我试图实现的目标。有什么原因吗?也许尝试直接在IIS上使用本地用户,而不是使用服务自动验证,可以让您查看错误是在配置上还是在代码上。为此,请在部署您的服务的文件夹上为用户授予读取权限。我将尝试一下。那么我需要在我的文件中配置用户/密码吗?最后,我需要实现System.IdentityModel.Selectors.UsernamePasswordValidator否,不需要。IIS使用windows进行身份验证。别忘了删除配置中的ServiceCredencial