"The HTTP request is unauthorized with client authentication scheme 'Anonymous'"



我有一个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>

它期待Windows身份验证,您是否与服务器位于同一域中? 如果您是,则需要像这样打开Windows身份验证:

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

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

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

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

这就是 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中执行此操作,则必须记住一直执行此操作,否则它将在您再次发布时重置。

希望这会帮助某人。

相关内容

最新更新