当客户端甚至无法连接到 WCF 服务器时,为啥会出现“服务器堆栈跟踪”异常?

Posted

技术标签:

【中文标题】当客户端甚至无法连接到 WCF 服务器时,为啥会出现“服务器堆栈跟踪”异常?【英文标题】:Why do I get an exception with "server stack trace" when the client can't even connect to WCF server?当客户端甚至无法连接到 WCF 服务器时,为什么会出现“服务器堆栈跟踪”异常? 【发布时间】:2012-12-12 01:58:36 【问题描述】:

在我的代码中,我向 https:// 端点发出 WCF 请求。有时 WCF 服务器会由于某种原因无法访问,然后我的代码会产生异常:

System.TimeoutException
The request channel timed out while waiting for a reply after 00:01:00.
Increase the timeout value passed to the call to Request or increase
the SendTimeout value on the Binding. The time allotted to this operation
may have been a portion of a longer timeout.

并且异常的.StackTrace 包含以下文本:

Server stack trace: <<<< THE QUESTION IS ABOUT THIS VERY LINE
   at System.ServiceModel.Channels.RequestChannel.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 [my code here invoking an OperatiionContract-attributed method

.InnerException 是另一个TimeoutException,带有以下消息:

The HTTP request to 'https://management.core.windows.net/subscription-id-here/
   services/hostedservices/service-name-here/deployments/deployment-id-here'
has exceeded the allotted timeout of 00:01:00. The time allotted to this
operation may have been a portion of a longer timeout.

我不明白的是Server stack trace 措辞。

如果我的请求甚至没有得到服务器响应,为什么它是“服务器”?

【问题讨论】:

您确定客户端请求没有到达 WCF 服务吗?也许服务上有一些例外 尝试增加1:00 的任何超时时间,看看效果是否更好。 @John Saunders:就像我会得到一个不提及“服务器跟踪”的异常? 就像你可能会得到一个不同的异常——一个不同的异常。 @John Saunders:嗯,问题肯定不在我这边,我只是想知道为什么这里提到了“服务器堆栈跟踪”。 【参考方案1】:

连接两端都可能发生超时;客户端或服务器。因此,根据您的例外情况,我会说客户端连接到服务器,但由于未及时生成响应(基于服务器对 sendTimeout 的绑定),WCF 响应如您所见。

有关超时设置的更多信息,请参阅http://msdn.microsoft.com/en-us/library/hh924831(v=vs.110).aspx。

【讨论】:

以上是关于当客户端甚至无法连接到 WCF 服务器时,为啥会出现“服务器堆栈跟踪”异常?的主要内容,如果未能解决你的问题,请参考以下文章

为啥客户端无法连接到 Java Websocket 服务器?

无法连接到我的Localhost上的WCF服务

如何在 IIS 中正确托管连接到 SQLServer 的 WCF 数据服务?为啥我会收到错误消息?

netstat 说 443 已打开,但我无法使用 telnet 连接到它.. 为啥?

使用 gSOAP 连接到 WCF Web 服务

csgo连接到任意服务器失败为啥?