我有一个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>
答案 0 :(得分:1)
它期待Windows身份验证,您与服务器位于同一个域吗?如果你是,你将需要打开这样的Windows身份验证:
<security>
<transport clientCredentialType="Windows" proxyCredentialType="None" />
<message clientCredentialType="Windows" />
</security>
如果您不想打开它,可以打开其他身份验证类型,如匿名或证书。请参阅:
http://msdn.microsoft.com/en-us/library/ms729700.aspx
注意:有时如果从您正在呼叫的计算机启用了代理服务器,它也会遇到此类问题。在这种情况下,请关闭代理或向代理提供身份验证。
答案 1 :(得分:1)
这就是Bravo11所说的...... 这真的困扰了我一段时间,但我在尝试了上述许多不同的方法后终于遇到了解决方案。在vs2010中创建服务时,如果要将Windows添加为安全性,则需要将身份验证模式设置为Windows。
<system.web>
<compilation debug="true" targetFramework="4.0" />
<authentication mode="Windows" />
</system.web>
您可以在服务中的Web.config中或在属性中的IIS 6.0中执行此操作 - &gt; ASP.NET - &gt;编辑配置 - &gt;身份验证 - &gt;身份验证模式下拉
如果您选择在IIS中执行此操作,则必须记住始终执行此操作,否则当您再次发布时它将重置。
希望这会对某人有所帮助。