簡體   English   中英

WCF wsHttpBinding 與 http keepalive

[英]WCF wsHttpBinding with http keepalive

我有一個使用 wsHttpBinding 的 WCF 客戶端,我想啟用 http keep-alive。

我希望我可以通過更改客戶端配置來打開它......我找到了很多關於如何為 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>

您必須使用自定義綁定才能禁用Keep-Alive header,因為該功能未在任何內置綁定類中公開。

無需從頭開始定義自定義綁定即可實現此目的的最簡單方法是在代碼中自定義與客戶端代理關聯的現有BasicHttpBindingWSHttpBinding實例。

這是一個例子:

var proxy = new MyServiceClient();
var customBinding = new CustomBinding(proxy.Endpoint.Binding);
var transportElement = customBinding.Elements.Find<HttpTransportBindingElement>();
transportElement.KeepAliveEnabled = false;

proxy.Endpoint.Binding = customBinding;

在所有基於 HTTP 的綁定上默認啟用保持活動,並且無法將其關閉。 如果您想關閉它,您必須創建全新的自定義綁定並將httpTransport綁定元素上的keepAliveEnabled設置為 false。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM