使用自定义类作为 JAX-WS 返回类型?
我正在使用 NetBeans 的 Web 服务生成工具。我查看了可用的教程,但找不到有关如何使用自定义类作为返回类型的任何内容。我读过的大多数教程并不比 Hello World 更复杂:它们接受并返回简单类型,例如字符串。
假设我想要一个具有 3 个字段的类:一个 String、一个 int 和一个 double[]。到目前为止,我传递自己的类的唯一方法是创建“信封类”,没有方法,无参数构造函数,并且所有字段都声明为公共。我更喜欢编写标准的 Java 类。显然,我无法通过 SOAP 发送方法,但我认为有一种方法可以在编组类时忽略这些方法,而只编组字段。
有人告诉我有注释可以促进这一点,但我找不到任何关于如何实现它们的教程。任何指导将不胜感激。
I'm using NetBeans's Web Service generation tools. I've looked at the tutorials available, but cannot find anything on how to use a custom class as a return type. Most of the tutorials I've read are no more complex than Hello World: they take and return simple types like Strings.
So say I want a class that has 3 fields: a String, an int and a double[]. So far, the only way I can pass my own classes is by creating "envelope classes", with no methods, a parameter-less constructor, and with all fields declared public. I'd prefer to write standard Java classes. Obviously I cannot send the methods across SOAP, but I would have thought there was a way to ignore the methods when Marshalling the class, and only Marshall the fields.
Somebody has told me there are Annotations that facilitate this, but I can't find any tutorials on how to implement them. Any guidance would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用 NetBeans 接口来设计您的 ws.
If you are using NetBeans interface to design your ws.
JAX-WS 使用 JAXB 来映射类型,因此类应该符合该规范。您可以在 中找到 JAXB 注释java.xml.bind.annotations 包。
如果您想编组未注释的类,请遵守 JavaBeans 的规则:
如果您想使用带参数的构造函数等,请查看 关于工厂方法和适配器的规范。
JAX-WS uses JAXB for mapping types, so classes should conform to that specification. You can find JAXB annotations in the java.xml.bind.annotations package.
If you want to marshal a non-annotated class, conform to the rules for JavaBeans should work:
If you want to use constructors with arguments, etc. look at the parts of the spec about factory methods and adapters.