2013-08-23 54 views
2

我已更改Web.Config並且該服務正在使用匿名身份驗證。儘管啓用了Windows身份驗證並且IIS7.5中禁用了匿名身份驗證,但它開始給我提供以下錯誤。請幫忙。WCF服務Windows身份驗證不起作用

主機 (「IntegratedWindowsAuthentication」)上配置的認證方案不允許 結合「basicHTTP」(「匿名」)的那些配置。請確保將 SecurityMode設置爲Transport或TransportCredentialOnly。 此外,這可以通過改變認證 方案爲通過IIS管理工具本申請中,通過 的ServiceHost.Authentication.AuthenticationSchemes屬性,則 應用配置文件中的 元件,通過在更新ClientCredentialType屬性來解決綁定, 或通過調整 HttpTransportBindingElement上的AuthenticationScheme屬性。

Web.config文件如下:提前

<?xml version="1.0"?> 
<configuration> 

<appSettings> 
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" /> 
    </appSettings> 
<system.web> 
<compilation debug="true" targetFramework="4.5" /> 
<httpRuntime targetFramework="4.5"/> 
</system.web> 
<system.serviceModel> 
<bindings> 
    <webHttpBinding> 
    <binding name="JSONBinding"></binding> 
    </webHttpBinding> 
    <basicHttpBinding> 
    <binding name="basicHTTP"> 
     <security mode="TransportCredentialOnly"> 
     <transport clientCredentialType="Windows"></transport> 
     </security> 
    </binding> 
    </basicHttpBinding> 
</bindings> 
<behaviors> 
    <serviceBehaviors> 
    <behavior name="basicBehavior"> 
     <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>  
     <serviceDebug includeExceptionDetailInFaults="false"/> 
    </behavior> 
    </serviceBehaviors> 
    <endpointBehaviors> 
    <behavior name="JSON"> 
     <webHttp/> 
    </behavior> 
    </endpointBehaviors> 
</behaviors> 
<services> 
<service name="RestWCFService.CalculationService" behaviorConfiguration="basicBehavior"> 
<endpoint address="" binding="basicHttpBinding" contract="RestWCFService.ICalculatorService" bindingName ="basicHTTP"></endpoint> 
    <!--  
    <endpoint behaviorConfiguration="JSON" binding="webHttpBinding" bindingConfiguration="JSONBinding" contract="RestWCFService.ICalculatorService" name="JSONService"></endpoint> 
    --> 
    </service>  
</services> 

<protocolMapping> 
    <add binding="basicHttpBinding" scheme="http"/> 
    <add binding="basicHttpsBinding" scheme="https" /> 
</protocolMapping>  
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> 
</system.serviceModel> 
<system.webServer> 
<modules runAllManagedModulesForAllRequests="true"/> 
    <!-- 
    To browse web app root directory during debugging, set the value below to true. 
    Set to false before deployment to avoid disclosing web app folder information. 
    --> 
    <directoryBrowse enabled="true"/> 
</system.webServer> 

</configuration> 

謝謝!

回答

2

您沒有在端點中使用名爲basicHTTP的基本HTTP綁定。將端點中的屬性從bindingName="basicHTTP"更改爲bindingConfiguration="basicHTTP"

順便說一下,您可能需要在IIS中啓用匿名身份驗證和Windows身份驗證。

+0

感謝您使用bindingConfiguration指出內容。更改它會導致另一個Windows身份驗證錯誤。雖然在Windows身份驗證中,我們不需要禁用匿名?錯誤是:在IIS上配置的擴展保護設置與傳輸上配置的設置不匹配。 ExtendedProtectionPolicy.PolicyEnforcement值不匹配。 IIS的值爲Always,而WCF傳輸的值爲Never。 –

+0

我從來沒有這樣的錯誤。無法幫助你。 – Yavuz

+0

基本上,由於IIS7.5 Windows身份驗證和擴展保護設置爲必需/始終與我一起發生錯誤。無論如何謝謝讓我擺脫以前的錯誤。謝謝。 –