簡體   English   中英

服務器關閉保持活動狀態的HTTP連接時檢測或避免客戶端CommunicationException

[英]detecting or avoiding client CommunicationException when server closes keep-alive http connection

我正在為運行嵌入式Linux的設備(發生Pelco品牌的視頻快球)中的SOAP服務開發VS2010 Dotnet 4.0客戶端。 我無法控制設備中的SOAP服務器。 供應商提供了可正確加載的WSDL文件作為服務引用。

我正在使用命令行桌面客戶端來解決此問題(在將代碼遷移到服務中之前)。

簡化一下,各種服務中的SOAP調用采用如下形式:

 service.SetPosition(pan,tilt,zoom)
 var pos = service.GetPosition();

等等。 他們基本上可以正常工作並完成預期的工作。

問題是這樣的:有時,間歇地,以我還沒有弄清楚的模式,這些服務調用中的一個隨機調用引發CommunicationException,其Message為

 The underlying connection was closed: A connection that was 
 expected to be kept alive was closed by the server.

這是我構造服務對象的方式:

  var binding = new System.ServiceModel.BasicHttpBinding();
  uri = new Uri(/*the correct uri for the service*/);
  address = new System.ServiceModel.EndpointAddress(u);
  service = new PositioningControlPortTypeClient(binding, address);

在這種情況下,當我將其作為服務引用加載時,通過WSDL定義了PositioningControlPortTypeClient

有沒有一種方法可以強制dotnet 4.0 / wcf / soap使用HTTP / 1.0?

有沒有辦法在拋出異常之前檢測到我的服務客戶端即將拋出該異常?

我是否應該只使用每個服務對象一次,然后處置它?

還有其他智慧嗎?

您可以嘗試在綁定中禁用Keep-alive:

  var binding = new System.ServiceModel.BasicHttpBinding();
  uri = new Uri(/*the correct uri for the service*/);
  address = new System.ServiceModel.EndpointAddress(u);
  CustomBinding cbinding = new CustomBinding(binding);
  foreach (BindingElement be in cbinding.Elements)
  {
      if (be is HttpTransportBindingElement) ((HttpTransportBindingElement)be).KeepAliveEnabled = false;
  }
  service = new PositioningControlPortTypeClient(cbinding, address);

暫無
暫無

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

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