VS2010 中跨多个 Web 服务的通用 DTO
我有一组共享通用 DTO 模型的 WCF Web 服务。
问题是,当我在 Visual Studio 2010 中添加服务引用时,为每个 Web 服务生成的代理都有自己的命名空间(解决方案内部),这意味着我在每个服务引用上本质上都有重复的 DTO。
有没有一种干净的方法来克服这个问题并共享 dto,而不是在整个服务组上创建一个外观?
干杯。
I have a collection of WCF web services that share a common DTO model.
The problem is that when I add service references in Visual Studio 2010, the proxy generated for each of the web services has its own namespace (internal to the solution), meaning that I essentially have duplicate DTO's on each of the service references.
Is there a clean way to get over this and to share the dto, short of creating a facade over the whole group of services?
Cheers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 Visual Studio 的命令行工具 svcutil.exe 生成客户端代理,而不是通过 Visual Studio“添加服务引用”功能创建客户端代理。将 URL 传递给每个服务的元数据,svcutil 应该找出它们共有的类型。
.Net 使用 Web 服务:相同类型在两种不同的服务中
我不确定是否有更简单/更好的方法。
Instead of creating your client proxies via the Visual Studio "Add Service Reference" functionality, you could generate them using Visual Studio's command line tool svcutil.exe. Pass in the URL to the metadata for each service and svcutil should figure out what types they have in common.
.Net Consuming Web Service: Identical types in two different services
I'm not sure if there is an easier / better way.
您应该将 DTO 放在单独的库中。在您的客户端项目中添加对该库的引用。您可以将代理生成配置为引用库中使用的对象。
右键单击您的服务引用并选择配置服务引用,应该有一个“引用程序集中的重用类型”选项。
You should have the DTO in a seperate library. Add a reference to that library in your client project. And you can configure the proxy generation to used object from referenced library.
Right click on your service reference and select configure Service reference there should be an option for Reuse types in referenced assemblies.