1

I'm developing a WPF Client which interacts with a WCF Web Service which persists data on a database using NHibernate.

I understand that I can add a service reference to my Client in order to generate classes from the Web Service's metadata. These classes would then allow me to interact with my Service by simply instantiating objects and calling methods using them.

My question is:

Should I simply use these objects as-is, or are there any possible improvements by "wrapping" the service calls in a class which handles all communications with the Web Service ?

In other words, would creating a proxy in my client everytime I want to communicate with my service be costly performance-wise ? If so, would I need to create a class which "wraps" the generated classes and which holds on to a channel ?

What are some improvements that you can recommend besides simply creating a proxy and using it to interact with a Service ?

Thanks

Nivid Dholakia
  • 5,272
  • 4
  • 30
  • 55
Hussein Khalil
  • 1,585
  • 2
  • 25
  • 47

1 Answers1

1

Allow me to direct you toward this article which talks about the caching of channels in the client proxy.

Jesse C. Slicer
  • 19,901
  • 3
  • 68
  • 87
  • Thank you Jesse, I will take a look at the article. This might be exactly what I need. – Hussein Khalil Aug 30 '11 at 15:37
  • 2
    You should also [look at this question and the answers](http://stackoverflow.com/questions/573872/what-is-the-best-workaround-for-the-wcf-client-using-block-issue) for suggestions on dealing with how WCF implemented the Dispose pattern for ClientBase inherited proxies. If you write your own wrapper for generated proxies, you'll need to take this into account. – Sixto Saez Aug 30 '11 at 15:44
  • Wow, Sixto, that got me thinking, thanks! To the point I wanted to create my own answer to that as well: http://stackoverflow.com/questions/573872/what-is-the-best-workaround-for-the-wcf-client-using-block-issue/7248638#7248638 – Jesse C. Slicer Aug 30 '11 at 19:25
  • 1
    From reading Jesse's link and browsing around the web, I understood that since .NET 3.5 the Channel Factory is automatically cached for you (most of the time) if you use SVCUTIL's auto-generated proxies. The conditions are detailed in the article. As for Sixto's link, you can find a solution to the Dispose problem here (for Visual Studio 2010): http://wcfproxygenerator.codeplex.com/SourceControl/list/patches. This addin will replace Visual Studio's Service Reference proxy generation tool with one that generates proxies that properly handle exceptions. In short, no wrapper is necessary. :) – Hussein Khalil Aug 30 '11 at 22:12