如何创建和管理wcf服务客户端?

发布于 2024-09-08 07:36:44 字数 695 浏览 5 评论 0原文

起初,我将它们视为任何依赖项,将它们在构造函数中传递给使用服务的类:

var serviceConsumer = new ServiceConsumer(new MailingServiceClient())

问题是,一旦从服务抛出异常,它就会进入错误状态,并且不会回复任何请求,因此需要重新初始化到期的。

此外,我逐渐熟悉了以下事实:wcf 服务可能多次无法正确处置,因为生成的代理的处置方法已损坏(调用关闭而不检查故障状态),并遇到了几种方法来克服该问题:

  1. 包装对每项服务的每次调用。
  2. 覆盖 scvutil.exe 生成的类的默认 IDisposable 行为

因为我不会就像消费者代码出于测试原因自己创建服务客户端一样,我的问题是:

  • 如何维护工作的无故障服务?

  • 我怎样才能仍然使用依赖注入来实现可测试性?

At first I treated them as any dependency passing them in the ctor to the class consuming the service:

var serviceConsumer = new ServiceConsumer(new MailingServiceClient())

The problem was that once an exception was thrown from the service it entered a faulted state and would not reply to any requests, so re-initialization was due.

Further more, I became familiar with the fact that wcf services may not be disposed properly on several occasions, because the dispose method of the generated proxy is broken (calls close without checking the fault state) and encountered a couple of ways to overcome that:

  1. wrapping every call to every service.
  2. override the default IDisposable behavior of the scvutil.exe-generated class

Since I wouldn't like the consumer code to create the service client himself for testing reasons, my questions are:

  • how can I maintain a working un-faulted service?

  • how can I still use dependency injection for testability?

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

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

发布评论

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

评论(1

吾家有女初长成 2024-09-15 07:36:44

找到了一个很好的解决方案。

一个替代 VS 的代理生成器,并在默认代理周围生成一个包装器,用于处理代理故障、超时和正确处理。

http://wcfproxygenerator.codeplex.com/

似乎对我来说工作得很好。

Found a nice solution.

a proxy generator that replaces the VS one, and generates a wrapper around the default proxy that deals with proxy faults, timeouts, and correct disposal.

http://wcfproxygenerator.codeplex.com/

seems to be working fine for me.

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