2013-10-31 103 views
0

我正在嘗試設置一個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位專業版+所有更新)。

任何人都可以協助嗎?

+0

使用BasicHttpBinding和userName身份驗證時,WCF中的基本規則是您無法通過http傳遞用戶名/密碼,因爲http傳輸是明文。因此,您必須啓用使其成爲https的傳輸安全性。 – Rajesh

+0

儘管我同意你的評論,但我原來的問題是Windows Phone 8不支持https username auth - 這就是爲什麼我必須使用basicHttpBinding和用戶/密碼。讓我知道如果這是不正確 – Computer

回答

1

根據錯誤,您需要設置IIS以允許您的服務使用「基本身份驗證」。

在IIS管理控制檯中,選擇身份驗證選項卡並設置允許「基本身份驗證」。另外,禁用「匿名身份驗證」。

如果「基本身份驗證」不在那裏,您需要將此角色添加到您的IIS。 檢查如何操作here

+0

謝謝米格爾。我改變了我的配置文件(請參閱原文)。當我通過瀏覽器連接到服務時,我得到一個提示輸入用戶名和密碼,但輸入user1 /密碼不會讓我進入服務頁面。但是,允許匿名身份驗證不會影響我試圖實現的目標。這是爲什麼? – Computer

+0

也許嘗試直接在IIS上使用本地用戶,而不是使用服務驗證可以讓您查看錯誤是在配置還是在代碼上。 爲此,在部署服務的文件夾上爲用戶提供讀取權限。 – ByteArtisan

+0

我會給你一個鏡頭。所以我需要在我的文件中的用戶/密碼配置?最後,我需要實現System.IdentityModel.Selectors.UserNamePasswordValidator – Computer

相關問題