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?
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.
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.
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.
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")]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With