WCF和Windows身份验证无法正常工作

时间:2011-07-11 04:47:12

标签: .net wcf web-config iis-7.5

我无法让我的WCF服务于Windows身份验证

如果我允许匿名一切正常,没有错误。

我在Windows 2008 r2标准SP1上运行.Net 3.5 IIS 7.5,如果重要的是VS 2010

我已经使用WCF服务配置编辑器来尝试验证我在做什么,但仍然没有运气

我在等待20-30秒后得到错误

Security settings for this service require 'Anonymous' Authentication but it is not enabled for the IIS application that hosts this service. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.NotSupportedException: Security settings for this service require 'Anonymous' Authentication but it is not enabled for the IIS application that hosts this service.

我的web.config是

  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>

    <bindings>
      <basicHttpBinding>
        <binding name="AmjBasicHttpEndpointBinding">
          <security mode="None">
            <transport clientCredentialType="Windows" />
          </security>
        </binding>
      </basicHttpBinding>

    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="SMS.Services.BEIMBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service behaviorConfiguration="SMS.Services.BEIMBehavior" name="SMS.Services.BEIM">
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="AmjBasicHttpEndpointBinding"
          name="BeimServices" contract="SMS.Services.IBEIM">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>

  </system.serviceModel>

EDIT 错误消息在网页上。 http://Servername/Directory/pageName.svc

4 个答案:

答案 0 :(得分:2)

嗯,事实证明:

  

此服务的安全设置需要“匿名”身份验证,但未为承载此服务的IIS应用程序启用。

仔细阅读邮件,您将看到需要为托管服务的IIS应用程序启用匿名身份验证。 (在IIS配置中)。

答案 1 :(得分:1)

IIS中托管的HTTP端点的WCF传输安全性要求在您的托管上应用相同的安全设置。转到IIS管理器并为托管应用程序配置身份验证到Windows身份验证并关闭其他身份验证模式。

正如@Kieren在评论中指出的那样,您将安全模式设置为None。所以你说你的服务不需要任何安全性。您应该将其更改为Transport,但它也需要HTTPS而不是HTTP端点。如果您坚持使用HTTP并且您对通过不安全通道传递安全令牌感到满意,则应将其更改为TransportCredentialOnly

答案 2 :(得分:0)

您是否更改了客户端的配置? 您的客户端应该使用相同的安全机制。请确认您的Windows凭据已传递给服务器。

答案 3 :(得分:0)

我已经在我的笔记本电脑中使用Win7在IIS7中托管了一个WCF。 WCF使用SSL并且只使用基本身份验证,一切正常。我使用Win server 2008 R2在另一台机器上将相同的wcf完全迁移到IIS7中,我得到了与此处帖子相同的错误。解决方案是评论mex端点,现在一切正常。谢谢大家。