【问题标题】:"The HTTP request is unauthorized with client authentication scheme 'Anonymous'"“HTTP 请求未经客户端身份验证方案‘匿名’授权”
【发布时间】:2013-10-07 19:35:30
【问题描述】:

我有一个 wcf 应用程序。在我的本地计算机(Windows 7 和 IIS 7.5)上测试,它可以工作。但是在部署到开发服务器(Windows Server 2003、IIS 6)之后。我收到以下错误消息。

The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Negotiate,NTLM'.

Server stack trace: 
   at System.ServiceModel.Channels.HttpChannelUtilities.ValidateAuthentication(HttpWebRequest request, HttpWebResponse response, WebException responseException, HttpChannelFactory`1 factory)
   at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory`1 factory, WebException responseException, ChannelBinding channelBinding)
   at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at ICFIR.ProcessXmlMessage(String xmlDocument)
   at CFIRClient.ProcessXmlMessage(String xmlDocument)

Inner Exception:
The remote server returned an error: (401) Unauthorized.
   at System.Net.HttpWebRequest.GetResponse()
   at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)

我在谷歌上搜索了几个小时,发现了很多类似的问题,但没有一个可以解决。这是我的 web.config

<basicHttpBinding>
    <binding name="ServiceSoap" closeTimeout="00:01:00"
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
      allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
      maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
      messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
      useDefaultWebProxy="true">
        <readerQuotas maxDepth="32" maxStringContentLength="65536" maxArrayLength="16384"
          maxBytesPerRead="4096" maxNameTableCharCount="16384" />
        <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"
              realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
        </security>
    </binding>
</basicHttpBinding>

【问题讨论】:

    标签: wcf wcf-binding wcf-security


    【解决方案1】:

    它需要 Windows 身份验证,您与您的服务器在同一个域中吗?如果你是,你需要像这样打开 Windows 身份验证:

    <security>
      <transport clientCredentialType="Windows" proxyCredentialType="None" />
      <message clientCredentialType="Windows" />
    </security>
    

    如果您不想打开它,您可以打开其他身份验证类型,例如匿名或证书。参考这个:

    http://msdn.microsoft.com/en-us/library/ms729700.aspx

    注意:有时,如果您的代理服务器从您呼叫的机器启用,它也会出现此类问题。在这种情况下,请关闭您的代理或向代理提供身份验证。

    【讨论】:

    • ,我认为不需要身份验证。我不明白为什么它仍然期待 Windows 身份验证。
    • 另一个要查看的内容是在您的 IIS 网站或 Web 应用程序中,在身份验证下确保您已打开适当的身份验证方法。
    【解决方案2】:

    这就是 Bravo11 所说的...... 这确实困扰了我一段时间,但在尝试了上述许多不同的方法后,我终于找到了解决方案。在 vs2010 中创建服务时,如果要添加 Windows 作为安全性,则需要将身份验证模式设置为 Windows。

    <system.web>
        <compilation debug="true" targetFramework="4.0" />
        <authentication mode="Windows" />
    </system.web>
    

    您可以在服务中的 Web.config 或 IIS 6.0 中的属性 -> ASP.NET -> 编辑配置 -> 身份验证 -> 身份验证模式下拉菜单中执行此操作

    如果您选择在 IIS 中执行此操作,您必须记住始终执行此操作,否则当您再次发布时它会重置。

    希望这会对某人有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-10-27
      • 1970-01-01
      • 2019-09-13
      • 1970-01-01
      • 1970-01-01
      • 2011-06-22
      • 1970-01-01
      相关资源
      最近更新 更多