Gil Fink, Microsoft MVP, is an expert in Web development and Microsoft data platform. He works as a senior architect at Sela Group. He is currently consulting for various enterprises and companies, where he architects and develops Web and RIA-based solutions. He conducts lectures and workshops for developers and enterprises who want to specialize in infrastructure and Web development. He is also a co-author of several Microsoft Official Courses and training kits. You can read his publications at his blog: http://blogs.microsoft.co.il/blogs/gilf. Gil is a DZone MVB and is not an employee of DZone and has posted 124 posts at DZone. You can read more from them at their website. View Full User Profile

Add Service Reference – How to Avoid Generating Already Existing Classes

05.19.2010
| 2800 views |
  • submit to reddit
Today I was asked Add Service Reference – How to Avoid Generating Already Existing Objects how to avoid generating an already existing client class when we use the Add Service Reference menu item in Visual Studio.

The Problem

In the e-mail I got the question was regarding the use of ValidationResults (from the Validation Application Block) as a return type for a WCF Service. When they try to Add Service Reference to the service it is generating a new validationResults class for the use in the client side.

How to Avoid This Problem?

You need to reference the assembly that holds the ValidationResults in the client’s project. Since by default the Add Service Reference reuses the types in all the referenced assemblies this will disable the  generation of ValidationResults class. If you want to disable this feature or to be able to specify the referenced assemblies you can first open the Add service Reference menu and then click the Advanced button:



In the Service Reference Settings view you can check or uncheck the Reuse types in referenced assemblies checkbox or specify the only referenced assemblies to search with the Reuse types in specified referenced assemblies radio button:



Summary

In order to avoid generation of classes in the proxy that is generated by WCF’s Add Service Reference we need to add reference to the dll which include those classes in the client assembly. Another way to do that is to use the svcutil.exe with the parameter /reference:<file path> were file path is the location of the dll which you want to reuse its classes. I hope it will help you.
References
Published at DZone with permission of Gil Fink, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)