tags:

views:

26

answers:

1

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?

A: 

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.

AlonEl