WCF 服务 - 处理行为不良的客户端?
我们的 WCF 解决方案中有一个自定义侦听器,它继承自 ChannelListenerBase
。
我们有一个行为恶劣的客户端(超出我们的控制范围),它与我们进行 TCP 对话,内容如下:
SYN
SYN,ACK
RST
基本上,他们试图在套接字建立、失败和关闭套接字之前对其执行操作。
在我们的 OnEndAcceptChannel 代码中,我们最终无法创建通道,因为当我们到达那里时,底层 Socket 已经关闭,并且我们得到了 SocketException。这似乎杀死了监听器,阻止它接受进一步的连接。
从 OnEndAcceptChannel
开始,我们尝试返回 null、抛出异常以及对侦听器进行故障处理,以便可以在调用堆栈的更高层重新启动它。后者是我们发现的唯一允许通道有效地继续侦听的解决方案,但这具有终止所有已建立的服务连接的令人不快(且不可接受)的副作用。
有人对如何处理这种情况有任何建议,继续倾听,并且不失去已建立的连接......?
We have a custom listener on our WCF solution, which inherits from ChannelListenerBase<IDuplexSessionChannel>
.
We have a badly-behaved client (out of our control), which has a TCP conversation with us along the following lines:
SYN
SYN,ACK
RST
Basically, they're trying to perform operations on the socket before it's established, failing, and closing the socket.
In our OnEndAcceptChannel
code, we end up not being able to create a channel, because the underlying Socket has already been closed by the time we get there, and we get a SocketException. This then seems to kill the listener dead, stopping it accepting further connections.
From OnEndAcceptChannel
, we've tried returning null, throwing the Exception, and Faulting the listener so that it can be restarted higher up the call stack. The latter is the only solution we've found that will allow the channel to effectively keep on listening, but that has the unpleasant (& unacceptable) side effect of killing all established connections to the service.
Anybody got any suggestions of how to handle this situation, keep listening, and not lose established connections...?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们最终成功解决了这个问题。我们没有返回 null,而是返回了一个实现 IDuplexSessionChannel 的虚拟类的实例,该类本质上是一个哑状态机,仅此而已 - 愚弄 WCF 继续执行。
We managed to fix it in the end. Instead of returning null, we returned an instance of a dummy class implementing
IDuplexSessionChannel
that is essentially a dumb state machine, and nothing more - fools WCF into carrying on regardless.