VS2010 中跨多个 Web 服务的通用 DTO

发布于 2024-09-18 13:52:42 字数 202 浏览 1 评论 0原文

我有一组共享通用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

恋你朝朝暮暮 2024-09-25 13:52:42

您可以使用 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.

め七分饶幸 2024-09-25 13:52:42

您应该将 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文