当我添加服务引用时,为什么 VS2010 RC 不会使用我现有的类型? [英] Why won't VS2010 RC use my existing types when I add a service reference?

查看:23
本文介绍了当我添加服务引用时,为什么 VS2010 RC 不会使用我现有的类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 VS2010 RC 中获取服务引用以使用现有程序集时遇到了一个大问题.

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

即使我有一个类库,其中包含在服务项目和消费项目(这是一个类库)之间共享的所有数据契约(用 DataContract 标记的类和用 DataMember 标记的属性),当我添加服务引用时,使用服务引用而不是使用现有类型重新生成数据契约.

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.

当我使用 VS2010 beta 2 时,这运行良好,而且我有使用完全相同的数据契约的现有服务引用.但是如果我添加一个新的服务引用,甚至更新一个旧的,它就不会再使用现有的类型了.

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?

编辑以清除.它使用 svcutil.exe 生成代理类,并指向数据契约 dll,如下所示:

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

问题是,即使选中了重用"复选框并引用了数据合同程序集,Visual Studio 生成自己的数据合同而不是使用现有数据合同的可能原因是什么.

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.

推荐答案

我过去在 VS 2008 中遇到过这个问题.尽管我无法找到它为什么不从您添加服务引用的同一程序集中获取类型的原因,但我确实注意到如果您实际将 DataContracts 取出,它会起作用.就像将它们放在单独的 dll 中一样,然后将该 dll 引用到您要添加服务引用的项目.在大多数情况下,这是一个更优雅的解决方案,因为人们倾向于在服务和服务使用者之间共享数据契约.

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.

这篇关于当我添加服务引用时,为什么 VS2010 RC 不会使用我现有的类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆