问题描述
提示:这个问题有很多重复,但没有一个解决方案适合我.
Hint: This questions has many duplicates, but none of the solutions works for me.
我拥有的是一个 Web 服务和一个客户端,它们都引用了共享程序集DataModel".我正在使用添加服务引用..."对话框创建服务代理并选择在所有引用的程序集中重用类型",但它仍然创建新类型而不是重用我的类型.
What I have is a web service and a client, both having references to a shared assembly "DataModel". I'm creating the service proxy using the "Add service reference..." dialog and select "Reuse types in all referenced assemblies", but still it creates new types instead of reusing mine.
- 它曾经可以工作,但现在突然不再重用类型了
- 在添加服务引用之前引用共享程序集 不起作用
- 重新启动 VS2010 没有帮助(我有所有更新)
- 我尝试了一个简单的 POCO 类(只是一个包含整数属性的简单类),但也没有运气
- 删除并重新添加服务引用(或共享程序集引用)没有帮助
- 仅在在指定的引用程序集中重用类型"中选择共享程序集 - 没有运气
svcutil.exe/reference
产生相同的结果
- It used to work, but now suddenly it's not reusing types anymore
- Referencing the shared assembly before adding the service reference does not work
- Restarting VS2010 does not help (I have all updates)
- I tried with a simple POCO class (just a simple class containing an integer property), also no luck
- Deleting and re-adding the service reference (or the shared assembly reference) did not help
- Only selecting the shared assembly in "Reuse types in specified referenced assemblies" - no luck
svcutil.exe /reference
yields the same result
不知何故,我不知所措.还有其他解决方案吗?
I'm at wit's end somehow. Are there any other solutions?
我应该补充一点,我只是将我的项目重置为较早的提交,无论我使用哪个提交,仍然存在同样的问题.而且我知道它适用于早期的提交!
I should add that I just reset my project to earlier commits, and whichever commit I use, still the same problem. And I know it worked with earlier commits!
推荐答案
您需要这样做,或者至少在添加引用后更新服务引用.
You would need to do this, or at least update the service reference after adding the reference.
删除并重新添加服务引用(或共享程序集引用)没有帮助
你应该不需要这样做,但我也试过了.
and you shouldn't need to do this, but I would've tried it too.
为了重用"工作,两个项目(客户端和服务)需要使用相同版本的程序集.您正在引用该项目,这很好 - 由于版本不同,我之前在直接引用程序集时遇到过这种情况.
In order for the 'reuse' to work both projects (client and service) need to be using the same version of the assembly. You're referencing the project, which is good - I've encountered this before when referencing the assembly directly because of different versions.
这里还有一些其他的东西可以尝试
Here's some other things to try
- 为您的解决方案打开配置管理器" - 确保共享程序集已配置为构建.
- 确保您为客户端和服务使用项目参考 - 如果服务使用旧版本,则在客户端上使用最新程序集将无济于事.
- 删除项目引用和构建,并期望构建失败 - 如果它没有失败,那么您必须引用其他内容.
- 手动检查最新的共享程序集"是否包含在 服务和客户端的构建中 - 检查
bin
文件夹,检查程序集版本/构建日期.
- Open 'Configuration Manager' for your solution - make sure that the shared assembly is configured to build.
- Ensure you're using a project reference for both client and service - using the latest assembly on the client won't help if the service is using an older version.
- Delete the project reference and build, and expect the build to fail - if it doesn't fail then you must be referencing something else.
- Manually check that the latest 'shared assembly' is being included in the build in both service and client - check the
bin
folder, check the assembly version / build date.
如果所有其他方法都失败了,在双方强制使用相同对象的最佳方法是完全删除服务引用"代理并使用 ChannelFactory 方法.请参阅如何做的简单说明在不添加服务引用的情况下调用 WCF 服务 和 VS2010添加服务引用相对于直接 ClientBase 的优点.这是我首选的 WCF 模式,因为它不需要更新服务引用...",并删除所有生成的代理代码.
If all else fails, the best way to force the same object on both sides is to remove the 'service reference' proxy altogether and use the ChannelFactory method. See Simpler Explanation of How to Make Call WCF Service without Adding Service Ref and VS2010 Advantages of Add Service Reference over direct ClientBase<>. This is my preferred WCF pattern because it removes the need to 'Update service reference...', and removes all that generated proxy code.
这篇关于未重用的 WCF 常见类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!