开发者

Are auto-generated proxies the best approach for implementing an asynchronous WCF client?

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 las开发者_开发问答tName);

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?


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜