如何防止我的 .NET SOAP 客户端包含“Connection: KeepAlive”在 HTTP 标头中。 (使用WSE3.0)
在 HTTP 连接标头中,我的 Web 服务客户端包括: 连接:保持活动
我想禁用此功能。 经过一些研究,似乎实现此目的的方法是将 SoapHttpChannelOptions
类的 KeepAlive 成员设置为 false。但是,我没有看到在使用 WSE3.0(Web 服务增强)在 Visual Studio 中为我生成的 Web 服务客户端类 中访问/修改 SoapHttpChannelOptions
的方法。
就我而言,生成的存根类扩展了 Microsoft.Web.Services3.WebServicesClientProtocol
我在谷歌搜索中找不到任何示例,并且 SoapHttpChannelOptions 类的大多数成员都继承到 WebServicesClientProtocol 类中...
SoapHttpChannelOptions 参考
WebServicesClientProtocol 参考
注意:我没有尝试修改网络服务器。我正在尝试修改网络服务客户端。
In the HTTP Connection header, my web service client is including:Connection: Keep-Alive
I want to disable this.After doing some research, it appears the way to do this is to set the KeepAlive member of the SoapHttpChannelOptions
class to false. But, I do not see a way to access/modify SoapHttpChannelOptions
in the webservice client class that was generated for me in Visual Studio using WSE3.0 (Web Service Enhancement.
In my case, the generated stub class extends Microsoft.Web.Services3.WebServicesClientProtocol
I've been unable to find any examples searching google and most members of the SoapHttpChannelOptions class are inherited into the WebServicesClientProtocol class...
SoapHttpChannelOptions Reference
WebServicesClientProtocol Reference
Note: I'm not trying to modify the web server. I'm trying to modify the web service client.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种解决方案是重写
GetWebRequest(Uri uri)
方法。引导我找到此解决方案的信息在此 MSDN 论坛帖子
方法一:修改自动生成的文件。
将此代码段粘贴到自动为您生成的 Reference.cs 文件中。这种方法的缺点是,如果您重新生成 Web 服务客户端适配器(即更新 Web 引用),则必须再次修改该文件。
方法 2:创建分部类
创建一个文件并将以下代码粘贴到其中。修改命名空间和类名称,使其与您的 Web 服务匹配。
备注
如果您不使用 WSE,此方法可能有效。我能够将上面的方法粘贴到非 WSE Webservice 类下...它扩展了 System.Web.Services.Protocols.SoapHttpClientProtocol。从我的测试来看,这使得它根本不包含任何 Http Connection 行,就像我在 WSE 类(派生自
Microsoft.Web.Services3.WebServicesClientProtocol
)中执行此操作时,它然后包含“连接:关闭”行。根据 HTTP KeepAlive 网站:因此,虽然它可能不再在标头中包含 KeepAlive...我认为在 HTTP1.1 中它被假定为默认值。
One solution is to override the
GetWebRequest(Uri uri)
method.The information which lead me to this solution was found on this MSDN Forum Post
Method 1: Modify the Auto Generated file.
Paste this snippet into the Reference.cs file which was automatically generated for you. The downside of this approach is if you ever regenerate the web service client adapters (ie Update Web References) you will have to then modify the file again.
Method 2: Create a partial class
Create a file and paste the following code into it. Modify the namespace and class name so they match your webservice.
Notes
This approach may work if you do not use WSE. I was able to paste the method above under the non WSE webservice class... which extends
System.Web.Services.Protocols.SoapHttpClientProtocol
. From my testing it appeared that this made it not include any Http Connection line at all where as when I did it inside a WSE class (which are derived fromMicrosoft.Web.Services3.WebServicesClientProtocol
) it then included a "Connection: Close" line. According to this site on HTTP KeepAlive:So, while it may not include KeepAlive in the header anymore... I think in HTTP1.1 it's assumed to be the default.