【发布时间】: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