开发者

how to create and manage wcf service clients?

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开发者_JAVA技巧-faulted service?

  • how can I still use dependency injection for testability?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜