views:

243

answers:

2

I have a huge problem getting services references in VS2010 RC to use existing assemblies.

Even though I have a class library with all the data contracts (classes marked with DataContract and properties with DataMember) that is shared between the service project and the consuming project (which is a class library), when I add a service reference, the data contracts are regenerated withing the service reference instead of using the existing types.

When I was using VS2010 beta 2, this worked fine, and I have existing service references using the very same data contracts. But if I add a new service reference, or even update an old one, it won't use the existing types anymore.

I have made a mini-test-solution, with one service, one data contract type and one console app as a consumer (all in the same solution), and there it seems to work, but that's no great comfort to me. Is there any way to see why it can't use the existing types?

Edit to clearify. It works to generate the proxy classes with svcutil.exe, and point to the data contracts dll, like this:

svcutil.exe http://localhost/MyService.svc
/reference:[Path To DataContracts]\DataContracts.dll 
/n:*,MyProject.MyServiceReference /ct:System.Collections.Generic.List`1

The question is, what possible reason could there be for Visual Studio to generate its own datacontracts instead of using the existing ones even though the "reuse" checkbox is checked and the datacontracts assembly is referenced.

A: 

When you add a Service Reference there is a checkbox, that indicates if you want to generate the data contracts or use existing types.

I have not checked, but the default of this may have changed, which would explain your problem.

Shiraz Bhaiji
I believe this is on the Advanced tab.
John Saunders
Nope, that is checked. Rather, the checkbox is whether I want to reuse type from all referenced assemblies, or only the ones I specifically pick. Either way, it doesn't work.
Johan Driessen
A: 

I have had this problem with VS 2008 in the past. Although I wasnt able to find the reason why it doesnt pick up types from the very same assembly you are adding the service reference to I did notice that it works if you actually take the DataContracts out. As in put them in a separate dll and then reference that dll to your project where you are adding the service reference. In most case this is a more elegant solution anyway as people tend to share the DataContracts between the service and the service consumer.

Kyryll