2009-06-22 72 views
43

我很努力讓WCF服務在我們的服務器上的IIS上運行。部署完成後,我會收到一條錯誤消息:WCF - Windows身份驗證 - 安全設置需要匿名

此服務的安全設置需要「匿名」身份驗證,但未啓用承載此服務的IIS應用程序。

我想使用Windows身份驗證,因此我禁用了匿名訪問。還要注意,有aspNetCompatibilityEnabled(如果這有什麼區別)。

這裏是我的web.config:

<system.serviceModel> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> 
    <bindings> 
     <webHttpBinding> 
      <binding name="default"> 
       <security mode="TransportCredentialOnly"> 
        <transport clientCredentialType="Windows" proxyCredentialType="Windows"/> 
       </security> 
      </binding> 
     </webHttpBinding> 
    </bindings> 
    <behaviors> 
     <endpointBehaviors> 
      <behavior name="AspNetAjaxBehavior"> 
       <enableWebScript /> 
       <webHttp /> 
      </behavior> 
     </endpointBehaviors> 
     <serviceBehaviors> 
      <behavior name="defaultServiceBehavior"> 
       <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" /> 
       <serviceDebug includeExceptionDetailInFaults="true" /> 
       <serviceAuthorization principalPermissionMode="UseWindowsGroups" /> 
      </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <services> 
     <service name="xxx.Web.Services.RequestService" behaviorConfiguration="defaultServiceBehavior"> 
      <endpoint behaviorConfiguration="AspNetAjaxBehavior" binding="webHttpBinding" 
      contract="xxx.Web.Services.IRequestService" bindingConfiguration="default"> 
      </endpoint> 
      <endpoint address="mex" binding="mexHttpBinding" name="mex" contract="IMetadataExchange"></endpoint> 
     </service> 
    </services> 
</system.serviceModel> 

我都找遍了,沒有運氣互聯網。任何線索都不勝感激。

+3

問題應該確定它使用的是哪個版本的IIS。 – 2009-06-22 12:20:03

+0

版本是IIS 6.0 – Rashack 2009-12-07 12:17:24

+0

也請參考http://stackoverflow.com/questions/9588265/understanding-wcf-windows-authentication – Lijo 2012-10-24 05:45:33

回答

42

所以這似乎是很常見的問題。問題的關鍵是從你的綁定刪除MEX:

<endpoint address="mex" binding="mexHttpBinding" name="mex" contract="IMetadataExchange"></endpoint> 

Alternativelly您啓用IIS和你的web.config匿名訪問您確保匿名訪問被拒絕。

希望這會幫助別人的靈魂。 (我100%肯定我試過mex刪除。:-O)

+0

我最終使用了您的替代方案。帶有web.config的IIS匿名+ Windows拒絕所有匿名用戶。 我正在用asp.net託管3.5 WCF REST。 謝謝 – Nathan 2010-05-28 16:04:04

+6

其實,刪除mex不起作用。 – Andrey 2012-05-02 21:13:06

0

是的,它看起來像你需要完全刪除mex端點。設置

<serviceMetadata httpGetEnabled="false"/> 
單獨

沒有工作。謝謝!

14

您可以選擇這個one。 我設法使其按預期工作。

<configuration> 
    ... 
    <system.serviceModel> 
    ... 
    <bindings> 
     <basicHttpBinding> 
     <binding> 
      <security mode="TransportCredentialOnly"> 
      <transport clientCredentialType="Windows" /> 
      </security> 
     </binding> 
     </basicHttpBinding> 
    </bindings> 
    ... 
    </system.serviceModel> 
    ... 
</configuration> 
11

只是使用你的服務綁定爲mex。

所以更改當前的配置:

<endpoint address="mex" binding="mexHttpBinding" name="mex" contract="IMetadataExchange"></endpoint> 

<endpoint address="mex" binding="webHttpBinding" bindingConfiguration="default" name="mex" contract="IMetadataExchange"></endpoint> 

這應該解決的問題

0

其他解決方案:

你一定要確保服務名稱和合同是正確的。

希望它有助於某種方式。

2

匿名身份驗證可以,並且在某些情況下必須爲服務啓用而不是爲站點啓用。

因此,檢查您的網站的「根」身份驗證只啓用Windows身份驗證。然後展開您的網站,選擇'服務'文件夾,並確保您的服務啓用了Windows和匿名身份驗證。

我有相同的工作環境,只有在這些環境中的區別是服務的身份驗證。在我的情況下,問題不是由選定的提供商(Ntlm或Negotiate)造成的,而是用於網站和服務的身份驗證設置。

至少我有基本的MSSQL主數據服務網站&服務相同的錯誤消息,這是解決方案。我在運行服務時確實遇到了錯誤,但網站幾乎可以正常工作,MDS Explorer無法工作,因爲服務的身份驗證設置起初是錯誤的。創建新的MDS站點時,這種未命中配置的原因可能是MDS配置管理器中的一個錯誤?

所以在我的情況下,問題不是通過對web.config和ApplicationHost.config文件進行任何特殊編輯來解決的,我沒有對配置文件進行任何編輯。只需爲網站選擇正確的身份驗證設置,並在IIS管理器中提供服務即可。我不確定這是否屬於這種情況,但可能值得嘗試?

1

當我刪除'mex'端點並設置clientCredentialType ='Ntlm'時,它對我有用 我在SharePoint內託管我的WCF。

0

看來這個MEX綁定問題已在.NET 4.0中修復。將服務器的應用程序池.NET CLR版本從2.0更改爲4.0可解決此問題。