[英]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.