2

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

2 回答 2

1

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

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

于 2014-05-28T16:50:05.133 回答
1

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

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

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

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

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

于 2013-10-07T20:02:07.983 回答