使用连接:在Web服务器SOAP请求中关闭 [英] Using Connection: Close in webserver SOAP requests

查看:294
本文介绍了使用连接:在Web服务器SOAP请求中关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


基础连接已关闭:预期将保持活动状态的连接已由服务器关闭。

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

使用.Net 4.0 Web服务客户端与ONVIF网络设备进行通信时,我们经常会遇到此异常。

We're getting this exception frequently when using .Net 4.0 web service client to communicate with an ONVIF network device.

查看数据包捕获,这似乎是与HTTP规范不兼容的设备,并且在发送响应后关闭连接,这与 HTTP / 1.1 保持活动的默认设置相反。
这导致客户端(WCF)在服务器刚刚关闭连接时尝试重用该连接,

Looking at the packet captures, this seems to be a device that is non compliant with the HTTP spec and closing a connection after sending the response, against the HTTP/1.1 default of keeping it alive. This results in the client (WCF) trying to reuse the connection while the server has just closed it,

直到制造商可以解决此问题,我可以告诉Web服务/ SOAP客户端不要使用持久连接的方式?

Until the manufacturer can fix this, is there any way I can tell the web service/SOAP client NOT to use persistent connections?

请注意,修改标头以使用 Connection:Close 除非一直处于关闭状态,否则将无济于事,但是SOAP客户端希望它保持打开状态。

Note that modifying the header to use Connection: Close won't help unless as it's being closed anyway, but the SOAP client is expecting it to stay open.

推荐答案

基础 HttpWebRequest s在 HttpChannelFactory
这是从 HttpTransportBindingElement 公开了 KeepAliveEnabled 属性。

The underlying HttpWebRequests are created in the HttpChannelFactory used by the generated client classes. This is created from the HttpTransportBindingElement which exposes a KeepAliveEnabled property.

已创建绑定元素在 WSHttpBinding 类,并且可以通过覆盖 GetTransport()

The binding element is created internally in the WSHttpBinding class, and can be changed by overriding GetTransport().

private class WSHttpBindingNoKeepAlive : WSHttpBinding {
    public WSHttpBindingNoKeepAlive(SecurityMode securityMode)
        : base(securityMode) {
    }

    protected override TransportBindingElement GetTransport() {
        TransportBindingElement transport = base.GetTransport();
        if (transport is HttpTransportBindingElement) {
            ((HttpTransportBindingElement)transport).KeepAliveEnabled = false;
        }
        return transport;
    }
}

此已覆盖的 ...然后可以使用Binding 类:

WSHttpBindingNoKeepAlive clientBinding = new WSHttpBindingNoKeepAlive(SecurityMode.None);
EndpointAddress address = new EndpointAddress(this.deviceUrl);
WSNameSpace.WSClient client = new WSNameSpace.WSClient(clientBinding, address);

这篇关于使用连接:在Web服务器SOAP请求中关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆