views:

1438

answers:

3

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?

+2  A: 

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.

jeremcc
+2  A: 

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")]
Rich Reuter
A: 

You say "I defined the following attribute in the code"..

Where precisiely in the code did you add this Contract namespace attribute?

It would be more clear if you asked this in a comment to Rich's answer.
jeremcc
This is an assembly level attribute that can be defined anywhere, but usually those are put in AssemblyInfo.cs (for C# projects).It's just better to put them together in a single place.
Piotr Owsiak