tags:

views:

43

answers:

1

I am designing the architecture for a C#/.NET 3.5 project that will communicate between a client and a server via WCF. This will generally be a query-response system, so as an example, one of the service methods might look like this:

User GetUserByLastName(string lastName);

An additional stipulation is that the WCF client methods need to be invoked asynchronously so they don't adversely affect the responsiveness of the UI, as these methods may take significant time to execute in some cases.

I have a proof of concept in place that I have implemented according to Microsoft's documentation, so client proxies are automatically generated using the 'Add Service Reference' dialog in Visual Studio, and I check the option to include asynchronous methods.

This works fine as a proof of concept, but I have encountered numerous blog posts and other references that strongly recommend against the use of auto-generated proxies in a large-scale project. Several of these sources present alternatives involving manually creating proxies or dynamically creating proxies using reflection, but these solutions seem to invariably only implement synchronous WCF calls.

An auto-generated proxy for an asynchronous WCF client involves quite a bit of boiler plate code that I would hate to have to manually implement and maintain for each service and method.

So my question is:

Is it a bad idea to use auto-generated proxies for asynchronous WCF services and if so, is there a good alternative that does not involve significant manual maintenance of boiler-plate code?

+2  A: 

It is bad for several reasons and I am sure you have read them all on those blog posts. For me the main drawbacks are:

1) Channel creation is an utter mess and ugly and inefficient

2) It is not possible to cache ChannelFactory

3) Does not work well with DI

4) If you reuse the client, channel can get faulty and you have to code around it

5) It is code generation and if your code changes, you have to regenerate.

6) It does not save a lot of code, to be honest. Creating channel factory using the interface of the service (and caching it) and then creating the proxy is a few lines of code if you use web.config/app.config for setting up your end point.

Aliostad
Regarding your point 6, I have not yet seen an example that showed how to do this for async operations that did not involve a substantial amount of code just to implement the infrastructure required for a single service method. Any recommendations or references?
ElectricDialect
@ElectricDialect Have a look here: http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/3e581713-4986-48bd-97ee-1f63759187d4
Aliostad