Webservice 在 wsdl 中向客户端公开复杂类型
我(为了让事情变得简单)有两节课 1)抽象类A 2)从A继承了B类。
现在我使用方法“callMethod(A argument)” 这在 wsdl 中公开了我的抽象类。
但问题是,在客户端我希望能够知道 A 是 B 还是其他东西。我希望能够达到 B 类,因为它不在 wsdl 中,所以不可用。
我已经尝试过 KnownTypeAttribute 和 ServiceKnownTypeAttribute,但我无法让它工作。
当然,现在我可以创建一个使用 B 类型参数的虚拟方法,从而导致 B 类在 WSDL 中公开,但这是不专业的。
有什么想法吗? 多谢
I have (to make things easy) 2 classes
1) abstract class A
2) inherited class B from A.
now i'm using a method "callMethod(A argument)"
which is exposing my abstract class in the wsdl.
But the problem is that on the client side i want to be able to know if A is B or something else. And i want to be able to reach the Class B which is not available since it's not in wsdl.
I've tried KnownTypeAttribute and ServiceKnownTypeAttribute, but i'm not being able to getting it to work.
Now of course i can create a dummy method that uses a parameter of type B, and thus resulting in class B being exposed in WSDL, but that's unprofessional.
Any idea?
Thanks a lot
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了同样的问题,我发现的唯一一件事就是有一种公开类型的方法(尽管从长远来看我需要一个)。
问题是 wsdl 必须包含类型,以便客户端知道 B 的属性,否则您将永远无法使用 B 客户端。 B 的 wsdl 将包含它继承 A 的事实。
换句话说,在客户端,您的对象实际上是 A - 因为只有公共属性被序列化,如果 Web 方法传递 A,则 A 或 B 之间没有区别。
I've faced the same problem, and the only thing I found was to have a method that exposed the type (albeit I needed one in the long run).
The problem is that the wsdl has to contain the type in order that the properties of B are known on client side, otherwise you cannot ever use B client side. The wsdl for B will include the fact that it inherits A.
In otherwords on client side your object really is a A - as only public properties are serialized there's no difference between an A or a B if the webmethod passes an A.