明确将KeepAlive属性设置为FALSE [英] explicitly set the KeepAlive property to FALSE
本文介绍了明确将KeepAlive属性设置为FALSE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有异步Web服务调用的vb.net应用程序.但它抛出错误基础连接已关闭".谷歌它了很多小时后,我发现问题是保持我的连接处于活动状态.我如何将KeepAlive属性显式设置为FALSE.结果:
http://www.eggheadcafe.com/software/aspnet/30191651/disabling-keepalive.aspx [ ^ ]
在您的Web服务代码中覆盖GetWebRequest方法
例如
http://weblogs.asp.net/jan/archive/2004/01/28/63771.aspx [ ^ ]
例如
http://stackoverflow.com/questions/1527407/how-do-i-prevent-my-net-soap-client-from-includes-connection-keepalive-in-th [ 命名空间 YourNamespace { 使用 System.Diagnostics; 使用 System.Web.Services; 使用 System.ComponentModel; 使用 System.Web.Services.Protocols; 使用系统; 使用使用System.Xml.Serialization; /// < > /// 该局部类使得所有请求都可以指定 /// HTTP标头中的连接:关闭",而不是连接:KeepAlive". /// < /summary > 公共 部分 类 YourServiceNameWse :Microsoft.Web.Services3.WebServicesClientProtocol { 受保护的 覆盖 System.Net.WebRequest GetWebRequest(Uri uri) { System.Net.HttpWebRequest webRequest =(System.Net.HttpWebRequest) base .GetWebRequest(uri); webRequest.KeepAlive = false ; 返回 webRequest; } } }
解决方案I found this on google (search phrase is "webservice set keepalive false") - the 2nd link among 118,000 results:
http://www.eggheadcafe.com/software/aspnet/30191651/disabling-keepalive.aspx[^]
Override the GetWebRequest method in your web service code
e.g
http://weblogs.asp.net/jan/archive/2004/01/28/63771.aspx[^]
e.g
http://stackoverflow.com/questions/1527407/how-do-i-prevent-my-net-soap-client-from-including-connection-keepalive-in-th[^]
namespace YourNamespace { using System.Diagnostics; using System.Web.Services; using System.ComponentModel; using System.Web.Services.Protocols; using System; using System.Xml.Serialization; /// <summary> /// This partial class makes it so all requests specify /// "Connection: Close" instead of "Connection: KeepAlive" in the HTTP headers. /// </summary> public partial class YourServiceNameWse : Microsoft.Web.Services3.WebServicesClientProtocol { protected override System.Net.WebRequest GetWebRequest(Uri uri) { System.Net.HttpWebRequest webRequest = (System.Net.HttpWebRequest)base.GetWebRequest(uri); webRequest.KeepAlive = false; return webRequest; } } }
check this out
这篇关于明确将KeepAlive属性设置为FALSE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文