在 WCF 服务之间共享 DTO 对象
在问之前我就觉得这是一个愚蠢的问题,但我的大脑现在运转不太好。我有两个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以重用 svcutil 中的类型:
http://blogs.msdn.com/youssefm/archive/2009/10/09/reusing-types-in-referenced-assemblies-with-svcutil-sr-switch.aspx
You can reuse types in svcutil:
http://blogs.msdn.com/youssefm/archive/2009/10/09/reusing-types-in-referenced-assemblies-with-svcutil-s-r-switch.aspx
文章 “如何重用类型跨服务端点” 建议在客户端手动更新 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.