我正在嘗試設置一個Web服務,它具有用戶名和密碼才能訪問該服務。我正在使用此鏈接作爲指導http://www.codeproject.com/Articles/642997/Generate-username-authentication-based-on-basicHtt基於basicHttpBinding無證書的用戶身份驗證
我已經打了一個區域,我不能解決以下錯誤。在我的配置下面我收到此錯誤消息
在主機('匿名')上配置的身份驗證方案不允許在綁定'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位專業版+所有更新)。
任何人都可以協助嗎?
使用BasicHttpBinding和userName身份驗證時,WCF中的基本規則是您無法通過http傳遞用戶名/密碼,因爲http傳輸是明文。因此,您必須啓用使其成爲https的傳輸安全性。 – Rajesh
儘管我同意你的評論,但我原來的問題是Windows Phone 8不支持https username auth - 這就是爲什麼我必須使用basicHttpBinding和用戶/密碼。讓我知道如果這是不正確 – Computer