Why is VS2010 RC not using my existing types when I add a service link?

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

Despite the fact that I have a class library with all data contracts (classes labeled DataContract and properties with DataMember) that are shared between the service project and the consumption project (which is the class library), when I add a reference to the service, the data contracts are restored using a service reference instead of using existing types.

When I used VS2010 beta 2, it worked fine, and I have existing links to services using the same data contracts. But if I add a new service link or even update an old one, it will no longer use existing types.

I made a mini-test solution with one service, one type of contract with data and one console application as a consumer (all in the same solution), and it works there, but there wasn’t much comfort for me, Is there any way to understand why it can't use existing types?

Change to clean. It works to create proxy classes using svcutil.exe and points to the dll of the dll data, for example:

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 is the possible reason for Visual Studio to generate its own datacontracts instead of using existing ones, even if the "reuse" checkbox is checked and the link to datacontracts is referenced.

+4
source share
2 answers

I had this problem with VS 2008 in the past. Although I could not find the reason why it does not select types from the same assembly, you add a link to the service, I noticed that it works if you really take DataContracts. As in the case of placing them in a separate dll, then refer to this DLL on your project, where you add a link to the service. In most cases, this is a more elegant solution, as people tend to share DataContracts between the service and the service consumer.

+1
source

When you add a link to a service, there is a checkbox that indicates whether you want to generate data contracts or use existing types.

I did not check, but by default this may change, which will explain your problem.

0
source

Source: https://habr.com/ru/post/1302049/


All Articles