Nat*_*han 12 .net configuration wcf keep-alive
我有一个使用wsHttpBinding的WCF客户端,我想启用http keep-alive.
我希望我可以通过更改客户端配置来启用它...我已经找到了很多关于如何打开basic-alives以进行basicHttp绑定的描述,但没有运气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>
Run Code Online (Sandbox Code Playgroud)
Enr*_*lio 22
您必须使用自定义绑定才能禁用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;
Run Code Online (Sandbox Code Playgroud)
默认情况下,所有基于 HTTP 的绑定都会启用“保持活动”状态,并且无法将其关闭。如果你想关闭它,你必须创建全新的自定义绑定并在绑定元素上设置keepAliveEnabled为 false 。httpTransport