WCF:包装遗留 API 问题

发布于 2024-09-09 19:45:43 字数 461 浏览 4 评论 0原文

我必须使用 WCF 服务包装旧版 .net 程序集 API(类和接口集)。服务被设想为代理,将调用委托给现有类,几乎不需要任何额外的工作。

因此,我添加了 [ServiceContract] 接口,它公开了处理现有结构和类的方法。但是 wcf-proxy-generator (svcutil) 删除了一些字段(声明为只读),并且对于别名来说不够智能(例如:public bool Boolean1 { get { return Booleans[0] }}变成 bool Boolean1 { get; })。

我决定复制此类遗留类以消除混乱。现在,一些现有的类和类都有合约安全版本。 WCF 服务具有额外的代码,可将契约安全类转换为遗留类和旧类。反之亦然。

您是否建议复制所有遗留类,或者只对有问题的类进行转换?可能我错过了一些额外的代理生成器参数。

先感谢您!

I have to wrap legacy .net assembly API (set of classes and interfaces) with WCF service. Service is visioned as proxy that delegates calls to existing classes with virtually no additional work.

So I addded [ServiceContract] interface that exposes methods that deals with existing structures and classes. But wcf-proxy-generator (svcutil) removed some fields (declared as read-only) and is not smart enough for aliases (for example: public bool Boolean1 { get { return Booleans[0] }} turned into bool Boolean1 { get; set; }).

I decided to duplicate such legacy classes in order to remove the confusion. Now there are contract-safe version for some of existing classes & WCF service has additional code that translate contract-safe classes into legacy ones & vise versa.

Would you suggest to duplicate all the legacy classes or is it ok to have conversion only for problem ones? May be there are some extra proxy generator parameters I missed.

Thank you in advance!

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

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

发布评论

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

评论(1

糖果控 2024-09-16 19:45:43

代理不喜欢只读属性,因为它需要序列化对象,并且如果无法调用 setter 并将序列化值放回到对象中,就无法做到这一点。

将遗留类修改为 WCF 友好会更容易,但通常这不是一个选项。您创建的用于从遗留类转换为 WCF 安全类的类看起来不错,但显然并不理想,因为您引入了另一个层只是为了将这些类与 WCF 一起使用。

The proxy doesn't like your read-only properties because it needs to serialize the object and can't do that without being able to call a setter and put the serialized value back into the object.

It would be easier to modify your legacy classes to be WCF-friendly, but typically that's not an option. The classes you created to convert from legacy class to WCF-safe class seem fine, but obviously not ideal as you introduce another layer just to use those classes with WCF.

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