在 WCF 服务之间共享 DTO 对象

发布于 2024-08-09 02:58:21 字数 894 浏览 2 评论 0原文

在问之前我就觉得这是一个愚蠢的问题,但我的大脑现在运转不太好。我有两个 WCF 服务“CountryService”和“FloristService”。

现在 CountryService 有以下方法:

IList<CountryDTO> GetAllCountries();

另外,FloristService 有一个方法:

bool AddFlorist(FloristDTO florist);

到目前为止一切都很好,但问题是 FloristDTO 引用了 CountryDTO 即

    public  string Address1 { get; set; }
    public  string Address2 { get; set; }
    public  string Address3 { get; set; }
    public  string City { get; set; }
    public  string Postcode { get; set; }
    public  CountryDTO Country { get; set; }
    public  string Name { get; set; }

这很好,但如果我使用 Visual Stuidos 生成 util 的服务代理(即添加引用> 添加服务引用)然后我创建了两个版本的 CountryDTO,即FloristService.CountryDTO 和 CountryService.CountryDTO。

现在我可以想到一些方法来克服这个问题,但似乎没有一个是正确的。我想知道“正确”的方法是什么,我可以使用代理生成工具做一些有趣的事情来使其共享通用的 DTO?

干杯,克里斯

I feel this is a stupid question even before asking, but my brain isn't working too well right now. I have two WCF services "CountryService" and "FloristService".

Now CountryService has the following method:

IList<CountryDTO> GetAllCountries();

Additionally, FloristService has a method:

bool AddFlorist(FloristDTO florist);

All good so far, but the problem is that the FloristDTO references a CountryDTO i.e.

    public  string Address1 { get; set; }
    public  string Address2 { get; set; }
    public  string Address3 { get; set; }
    public  string City { get; set; }
    public  string Postcode { get; set; }
    public  CountryDTO Country { get; set; }
    public  string Name { get; set; }

This is fine, but if I use the service proxy generating util with Visual Stuidos (i.e. Add Reference > Add Service Reference) then I get two versions of CountryDTO are created i.e.FloristService.CountryDTO and CountryService.CountryDTO.

Now I can think of a few ways to overcome this, but nonw of them seem right. I wondered what the "correct" approach to this would be, is there anything funky I can do with the proxy generation tool to make it share common DTOs?

Cheers, Chris

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

谜兔 2024-08-16 02:58:21

文章 “如何重用类型跨服务端点” 建议在客户端手动更新 Reference.svcmap 以包含多个 NamespaceMappings。

或者,svcutil 允许您一次指定多个端点并利用 /r(/reference) 和 /n(/namespace) 参数。

Article "How to reuse types across service endpoints" suggests on client side manually update Reference.svcmap to include multiple and NamespaceMappings.

Alternatively svcutil does allow you to specify multiple endpoints at a single time and utilize /r(/reference) and /n(/namespace) parameters.

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