WCF wsHttpBinding 与 http keepalive [英] WCF wsHttpBinding with http keepalive
问题描述
我有一个使用 wsHttpBinding 的 WCF 客户端,我想启用 http 保持连接.
I have a WCF client which uses a wsHttpBinding, I would like to enable http keep-alive.
我希望我可以通过更改客户端配置来打开它...我找到了很多关于如何为 basicHttp 绑定打开 keep-alives 的描述,但是 wsHttpBinding 没有运气...是这可能吗?
I'm hoping I can turn this on by just changing the client config... I've found plenty of descriptions of how to turn on keep-alives for a basicHttp binding, but no luck with wsHttpBinding... is this possible?
非常感谢.
这是我的客户端绑定:
<wsHttpBinding>
<binding name="WSHttpBinding_IRepositoryService" closeTimeout="00:00:10"
openTimeout="00:00:10" receiveTimeout="00:05:00" sendTimeout="00:05:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="655360" messageEncoding="Mtom"
textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="81920" maxArrayLength="163840"
maxBytesPerRead="409600" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="true" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="">
<extendedProtectionPolicy policyEnforcement="Never" />
</transport>
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
推荐答案
您必须使用 自定义绑定以禁用 Keep-Alive
标头,因为该功能未在任何内置绑定类中公开.
You'll have to use a custom binding in order to disable the Keep-Alive
header, since that feature is not exposed in any of the built-in binding classes.
无需从头开始定义自定义绑定即可实现此目的的最简单方法是自定义现有的 BasicHttpBinding 或 WSHttpBinding 与客户端关联的实例代码中的代理.
The easiest way to achieve this without having to define a custom binding from scratch, is to customize the existing BasicHttpBinding or WSHttpBinding instance associated to the client proxy in code.
这是一个例子:
var proxy = new MyServiceClient();
var customBinding = new CustomBinding(proxy.Endpoint.Binding);
var transportElement = customBinding.Elements.Find<HttpTransportBindingElement>();
transportElement.KeepAliveEnabled = false;
proxy.Endpoint.Binding = customBinding;
这篇关于WCF wsHttpBinding 与 http keepalive的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!