Add Service Reference – How to Avoid Generating Already Existing Classes

April 28, 2010

Add Service Reference – How to Avoid Generating Already Existing Classes

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:
Add Service Reference
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:
Service Reference Setting


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.

Add comment
facebook linkedin twitter email

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>