Add Service Reference – How to Avoid Generating Already Existing Classes
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:
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.
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)