Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Reuse existing types" is ignored when adding a service reference

I am adding a service reference to one of my projects in Visual Studio 2008. On the "Service Reference Settings" screen I am selecting the default option which says "Reuse types in all referenced assemblies". I have referenced the project for which I want to reuse a type. That type is being passed in as a parameter to a web method.

However, when the References.cs file is generated, it still creates a duplicate proxy version of that type. Is there something I am missing? Do you need to do anything special to the referenced type? Perhaps add some special attributes?

like image 246
jeremcc Avatar asked Sep 25 '08 15:09

jeremcc


People also ask

How do I add an existing service reference?

Open Microsoft Visual Studio. Open your project or create a new one. In the Solution Explorer right-click on YourSolution/YourProject/References. Select "Add Service Reference..." from the context menu.

What is reuse types in referenced assemblies?

It means that, if you control both the server code and client code and define the datacontract classes in a separate assembly (and add a reference to it in the client code), the svcutil will not generate new classes but instead will re-use your already-defined classes that you use for the server.


2 Answers

I've answered my own question (I think). What I was trying to do was use a service reference to point to an existing ASP.NET web service, but reusing types is not supported for old school web services. It only works with WCF services. So I took the plunge and converted my web service to a true WCF service and now it works fine.

like image 81
jeremcc Avatar answered Oct 15 '22 11:10

jeremcc


I had a similar problem until I defined the following attribute in the code so that the namespace of the objects related to the service contract were set to the same namespace as the commonly referenced types.

[assembly: ContractNamespace("YOUR_NAMESPACE_HERE")]
like image 42
Rich Reuter Avatar answered Oct 15 '22 10:10

Rich Reuter