处理客户端WCF服务重启

发布于 2024-08-16 03:22:07 字数 539 浏览 7 评论 0原文

我有一个 GUI 客户端,它运行在作为 Windows 服务托管的 WCF 服务上服务器盒。 WCF 服务在 PerCall InstanceContextMode 中运行,客户端有一个服务客户端的单例实例,我希望避免在每次调用时重新实例化该单例,因为这会让我的许多异步调用变得困难。

对我来说问题是,Windows服务重新启动后,每次客户端进行调用时都会收到如下异常消息:

此通道无法再用于发送消息,因为输出会话由于服务器启动的关闭而自动关闭。通过将 DispatchRuntime.AutomaticInputSessionShutdown 设置为 false 来禁用自动关闭,或者考虑修改远程服务器的关闭协议。

解决这个问题的最佳方法是什么?我可以在对服务客户端的所有调用周围放置 try-catch 子句,并在通信异常时重新实例化单例实例,但这将涉及大量样板代码。

I've got a GUI client which is running against a WCF services hosted as a Windows service on a server box. The WCF service is running in PerCall InstanceContextMode, and the client has a singleton instance of the service client and I want to avoid reinstantiating the singleton on every call as it makes life difficult for the many asynchronous calls I have.

The problem for me is, after the Windows service is restarted, everytime the client makes a call it gets an exception message like this:

This channel can no longer be used to send messages as the output session was auto-closed due to a server-initiated shutdown. Either disable auto-close by setting the DispatchRuntime.AutomaticInputSessionShutdown to false, or consider modifying the shutdown protocol with the remote server.

What's the best way to get around this? I can put try-catch clauses around all the calls to the service client and reinstantiate the singleton instance on communication exceptions but that will involve a lot of boilerplate code..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

疯狂的代价 2024-08-23 03:22:07

最好的办法是避免服务器上出现异常。如果 WCF 服务器遇到未被捕获和处理的异常,它将导致通道“故障”,使其变得无用。

在服务器端,您可以实现 IErrorHandler 接口 并捕获 .NET 异常,将它们转换为 SOAP 错误,并将其更优雅地返回给客户端,而不会导致通道出现故障。

这样,您可以捕获服务器上的所有 .NET 异常,并将它们转换为可互操作的 SOAP 错误,而不会导致这些问题。

有关详细信息,请参阅:

The best would be to avoid the exceptions on the server all together. If a WCF Server encounters an exception that is not being caught and handled, it will "fault" the channel, rendering it useless.

On the server side, you can implement the IErrorHandler interface and catch .NET exceptions, turning them into SOAP faults which will be handed back to the client more gracefully, without faulting the channel.

That way, you can catch all .NET exceptions on the server, and convert them into interoperable SOAP faults which will not cause these problems.

For more information, see:

别再吹冷风 2024-08-23 03:22:07

您可以看一下这个,也许可以避免一些样板代码:

http://wcfproxygenerator.codeplex.com

You can take a look at this to perhaps avoid some of that boilerplate code:

http://wcfproxygenerator.codeplex.com

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文