Add Service Reference - How to Avoid Generating Already Existing Classes
Join the DZone community and get the full member experience.
Join For FreeToday I was asked 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.
Published at DZone with permission of Gil Fink, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments