基于basicHttpBinding的用户身份验证,无需证书

时间:2013-10-31 20:55:31

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

我正在尝试设置一个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位专业版+所有更新)。

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

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

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

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

相关问题