.net WCF Windows 服务超时

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/919287/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 12:46:35  来源:igfitidea点击:

WCF Windows Service TimeOut

.netwindowswcfweb-servicesexception-handling

提问by rmdussa

I have a client application developed in .net seding a request to wcf service and supposed to send reponse .if execution time with in 1 minute,there is no error,if it exceeds 1 minute the error is

我有一个在 .net seding 中开发的客户端应用程序向 wcf 服务发出请求并应该发送响应。如果执行时间在 1 分钟内,则没有错误,如果超过 1 分钟,则错误是

Inner exception: This request operation sent to net.tcp://localhost:18001/PitToPort/2008/01/30/StockpileService/tcp did not receive a reply within the configured timeout (00:01:00).
The time allotted to this operation may have been a portion of a longer timeout. This may be because the service is still processing the operation or because the service was unable to send a reply message. Please consider increasing the operation timeout (by casting the channel/proxy to IContextChannel and setting the OperationTimeout property) and ensure that the service is able to connect to the client

内部异常:这个发送到 net.tcp://localhost:18001/PitToPort/2008/01/30/StockpileService/tcp 的请求操作在配置的超时时间 (00:01:00) 内没有收到回复。
分配给此操作的时间可能是较长超时的一部分。这可能是因为服务仍在处理操作或因为服务无法发送回复消息。请考虑增加操作超时(通过将通道/代理转换为 IContextChannel 并设置 OperationTimeout 属性)并确保服务能够连接到客户端

How to increase the time out and how? What is the best solution?

如何增加超时时间以及如何增加?最好的解决方案是什么?

采纳答案by rmdussa

I have add the following code to the Service app code

我已将以下代码添加到服务应用程序代码中

system.transactions  
    defaultSettings timeout="00:30:00" 

with this code the service will wait 30 minutes to get process done in database server and increase the

使用此代码,服务将等待 30 分钟以在数据库服务器中完成进程并增加

maxBufferSize="2147483647"  
maxReceivedMessageSize="2147483647"  
maxBufferPoolSize="2147483647" 

in client binding attributes, then it works fine.

在客户端绑定属性中,那么它工作正常。

Problem :Service is sending response but the client buffersize was less previously,I increased to maximum buffer size.

问题:服务正在发送响应,但客户端缓冲区大小以前较小,我增加到最大缓冲区大小。

回答by Yann Schwartz

Be careful, this error message is a boilerplate string WCF sends when it doesn't have a clue what happened. It really means "mmh something went wrong in the chain but I'm not really sure what, so, here's some trivia about the configuration, do what you want with it".

请注意,此错误消息是 WCF 在不知道发生了什么时发送的样板字符串。这真的意味着“嗯,链中出了点问题,但我不确定是什么,所以,这里有一些关于配置的琐事,用它做你想做的事”。

MOST OF THE TIME when you get this message it has nothing to do with actual timeouts. It can be quotas (number of objects in the graph, overall size, array length) or something that went wrong server-side, between the time your service method returned a result and the actual bytes were sent over the wire. So, you should check your configuration settings (and not the timeout, except if you had to actually wait for one minute to get the error. If you got the error straight away, it has nothing to do with timeouts whatsoever).

大多数情况下,当您收到此消息时,它与实际超时无关。它可以是配额(图中的对象数量、整体大小、数组长度)或服务器端出错的东西,在您的服务方法返回结果和实际字节通过线路发送之间。因此,您应该检查您的配置设置(而不是超时,除非您实际上必须等待一分钟才能收到错误。如果您立即收到错误,则与超时无关)。

This useless message is on top of my list of WCF annoyances.

这个无用的消息在我的 WCF 烦恼列表之上。

回答by marc_s

The timeout is called "sendTimeout" and you can configure it on your binding section in your config file, or in code - your choice.

超时称为“sendTimeout”,您可以在配置文件的绑定部分或代码中配置它 - 您的选择。

config:

配置:

  <system.serviceModel>
    <bindings>
      <netTcpBinding>
        <binding sendTimeout="00:03:00" />
      </netTcpBinding>
    </bindings>

This will set the timeout to 3 minutes.

这会将超时设置为 3 分钟。

Marc

马克

回答by Jed

I experienced this same error. Specifically, the exception that I received was:

我遇到了同样的错误。具体来说,我收到的例外是:

System.ServiceModel.CommunicationException: The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:09:59.9940000'.

System.IO.IOException: The write operation failed, see inner exception.

System.ServiceModel.CommunicationException: The socket connection was aborted.

This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue.

Local socket timeout was '00:09:59.9940000'.

System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host

System.ServiceModel.CommunicationException:套接字连接已中止。这可能是由于处理您的消息时出错或远程主机超过接收超时或底层网络资源问题引起的。本地套接字超时为“00:09:59.9940000”。

System.IO.IOException: 写操作失败,见内部异常。

System.ServiceModel.CommunicationException:套接字连接已中止。

这可能是由于处理您的消息时出错或远程主机超过接收超时,或底层网络资源问题引起的。

本地套接字超时为“00:09:59.9940000”。

System.Net.Sockets.SocketException: 一个现有的连接被远程主机强行关闭

The cause of my problem was due to the size of the message that was being sent from my WCF Client to the WCF Host. Apparently, the size of the message was too large.

我的问题的原因是从我的 WCF 客户端发送到 WCF 主机的消息的大小。显然,消息的大小太大了。

To fix the problem, I changed the hosts Web.Config maxReceivedMessageSizeattribute from 2097152to 8000000and the error no longer persisted.

为了解决这个问题,我将 hosts Web.ConfigmaxReceivedMessageSize属性从更改20971528000000并且错误不再存在。

Here's the Web.Config's attribute I'm referring to:

这是我指的 Web.Config 的属性:

<netTcpBinding>
<binding name="NetTCPBinding" maxReceivedMessageSize="8000000">
....
</binding>
</netTcpBinding>

The 8M message size that I chose was based on how large I "think" the message size is. I don't know of a way to explicitly determine the size of the actual WCF message that gets passed from the client to the host.

我选择的 8M 消息大小是基于我“认为”消息大小的大小。我不知道有什么方法可以明确确定从客户端传递到主机的实际 WCF 消息的大小。

回答by Deepesh

Check this out, for similar type of Error u have to set OperationTine out property http://www.codeproject.com/KB/WCF/WCF_Operation_Timeout_.aspx

检查一下,对于类似类型的错误,您必须设置 OperationTine out 属性 http://www.codeproject.com/KB/WCF/WCF_Operation_Timeout_.aspx

回答by Deepesh

If you know why the server is taking more than a minute to respond to the client, then you should extend the OperationTimeout of the channel (as it says in the error message).

如果您知道为什么服务器需要超过一分钟的时间来响应客户端,那么您应该扩展通道的 OperationTimeout(如错误消息中所述)。

Check out this, including a code sample at the end: http://final-proj.blogspot.com/2009/09/wcf-timeouts.html

看看这个,包括最后的代码示例:http: //final-proj.blogspot.com/2009/09/wcf-timeouts.html

Good luck.

祝你好运。

回答by goodguys_activate

Here is a far simpler solution... just set the property directly on the current ClientBase. In other words, first add a service reference, initalize it, then set the property "InnerChannel.OperationTimeout"

这是一个更简单的解决方案......只需直接在当前 ClientBase 上设置属性。换句话说,首先添加一个服务引用,初始化它,然后设置属性“InnerChannel.OperationTimeout”

NetUtilsWCF.SMTPDiagClient sClient = new NetUtilsWCF.SMTPDiagClient();

NetUtilsWCF.SMTPDiagClient sClient = new NetUtilsWCF.SMTPDiagClient();

sClient.InnerChannel.OperationTimeout = new TimeSpan(0, 5, 0);

sClient.InnerChannel.OperationTimeout = new TimeSpan(0, 5, 0);

回答by zhiyuan_

I got the same exception when using callback.It works in local test(the client and service program are running in the same machine) but not work in user environment(the service program runs in winserver 2008). The server code has executed in according to the log.I think it's because of environment or authority problem but have no idea how to handle.

我在使用回调时遇到了同样的异常。它在本地测试中有效(客户端和服务程序在同一台机器上运行)但在用户环境中不起作用(服务程序在 winserver 2008 中运行)。服务端代码根据日志执行完毕,我认为是环境或者权限问题,不知道怎么处理。

回答by Asokkumar

If you are facing the problem after correcting the config file then you may need to check this attribute. "OperationContract(IsOneWay:=True)".If you miss IsOneWay:=Trueattribute it may cause this problem.

如果您在更正配置文件后遇到问题,则可能需要检查此属性。 "OperationContract(IsOneWay:=True)".如果您错过了IsOneWay:=True属性,则可能会导致此问题。