如何增加asp.net中web服务的超时时间?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7279784/
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 15:52:21  来源:igfitidea点击:

How to increase the timeout period of web service in asp.net?

.netwinformsweb-servicestimeout

提问by Priyanka

I've created one web service which is of asmx type. And I'm using my web service in the .net windows application.

我创建了一个 asmx 类型的 Web 服务。我在 .net windows 应用程序中使用我的 web 服务。

Web method from the web service receives byte array conversion of the object & object of my class having different attributes in which i'm adding one xml file in the form of the string. When my string containing xml data increases then it gives me the "Time out" error while sending data to the the web service.

来自 Web 服务的 Web 方法接收具有不同属性的类的对象和对象的字节数组转换,其中我以字符串的形式添加一个 xml 文件。当我的包含 xml 数据的字符串增加时,它会在向 Web 服务发送数据时出现“超时”错误。

How to increase the timeout period of web service?

如何增加web服务的超时时间?

采纳答案by Davide Piras

you can do this in different ways:

你可以用不同的方式做到这一点:

  1. Setting a timeout in the web service caller from code (not 100% sure but I think I have seen this done);
  2. Setting a timeout in the constructor of the web service proxy in the web references;
  3. Setting a timeout in the server side, web.config of the web service application.
  1. 通过代码在 Web 服务调用者中设置超时(不是 100% 确定,但我想我已经看到了);
  2. 在 web 引用中的 web 服务代理的构造函数中设置超时;
  3. 在服务器端设置超时,web 服务应用程序的 web.config。

see here for more details on the second case:

有关第二种情况的更多详细信息,请参见此处:

http://msdn.microsoft.com/en-us/library/ff647786.aspx#scalenetchapt10_topic14

http://msdn.microsoft.com/en-us/library/ff647786.aspx#scalenetchapt10_topic14

and here for details on the last case:

在这里了解最后一个案例的详细信息:

How to increase the timeout to a web service request?

如何增加 Web 服务请求的超时时间?

回答by MOH3N

1 - You can set a timeout in your application :

1 - 您可以在应用程序中设置超时:

var client = new YourServiceReference.YourServiceClass();
client.Timeout = 60; // or -1 for infinite

It is in milliseconds.

它以毫秒为单位

2 - Also you can increase timeout value in httpruntime tag in web/app.config :

2 - 您也可以在 web/app.config 中的 httpruntime 标记中增加超时值:

<configuration>
     <system.web>
          <httpRuntime executionTimeout="<<**seconds**>>" />
          ...
     </system.web>
</configuration>

For ASP.NET applications, the Timeoutproperty value should always be less than the executionTimeoutattribute of the httpRuntimeelement in Machine.config. The default value of executionTimeoutis 90 seconds. This property determines the time ASP.NET continues to process the request before it returns a timed out error. The value of executionTimeoutshould be the proxy Timeout, plus processing time for the page, plus buffer time for queues. -- Source

对于 ASP.NET 应用程序,Timeout属性值应始终小于Machine.config 中httpRuntime元素的executionTimeout属性。executionTimeout的默认值为90 秒。此属性确定 ASP.NET 在返回超时错误之前继续处理请求的时间。executionTimeout的值应该是代理超时,加上页面的处理时间,加上队列的缓冲时间。--来源

回答by user1012506

In app.config file (or .exe.config) you can add or change the "receiveTimeout" property in binding. like this

在 app.config 文件(或 .exe.config)中,您可以在绑定中添加或更改“receiveTimeout”属性。像这样

<binding name="WebServiceName" receiveTimeout="24:00:00" />