Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Add Service Reference – How to Avoid Generating Already Existing Classes

DZone's Guide to

Add Service Reference – How to Avoid Generating Already Existing Classes

·
Free Resource
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.
Topics:

Published at DZone with permission of Gil Fink, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}