我有一个使用wsHttpBinding的客户端,我想启用http keep-alive。
我希望我可以通过更改客户端配置来打开它...我已经找到了很多关于如何为basicHttp绑定打开keep-alives的描述,但在wsHttpBinding上却一无所获……这个是可能的吗?
非常感谢。
下面是我的客户端绑定:
<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>发布于 2011-06-30 21:25:33
您必须使用custom binding来禁用Keep-Alive头,因为该特性不会在任何内置绑定类中公开。
要实现这一点而不必从头开始定义自定义绑定,最简单的方法是在代码中自定义与客户端代理关联的现有BasicHttpBinding或WSHttpBinding实例。
下面是一个例子:
var proxy = new MyServiceClient();
var customBinding = new CustomBinding(proxy.Endpoint.Binding);
var transportElement = customBinding.Elements.Find<HttpTransportBindingElement>();
transportElement.KeepAliveEnabled = false;
proxy.Endpoint.Binding = customBinding;发布于 2011-06-30 21:25:44
默认情况下,所有基于HTTP的绑定都启用了Keep alive,并且无法将其关闭。如果要将其关闭,则必须创建全新的自定义绑定,并在httpTransport绑定元素上将keepAliveEnabled设置为false。
https://stackoverflow.com/questions/6535074
复制相似问题