有效的 Java @WebMethod 返回类型是什么?
我正在使用 Java 编写一个 WebService。现在我有一个 @WebMethod 应该返回一些数据,但我不确定要使用什么格式。我看到在其他语言中,@WebMethod 返回类型有一定的限制 - 这对于 Java 来说是一样的吗?
当我尝试返回包含 XML 的 DOM 文档时,出现错误“无法创建 JAXBContext”,因此我将其更改为仅返回字符串数组。然而,从该数组获取内容相当乏味。有人有更好的解决方案吗?
谢谢,
素食聪明人
I am writing a WebService using Java. Now I have a @WebMethod that is supposed to return some data, and I am not sure what format to use. I have seen that in other languages, there are certain restrictions on @WebMethod return types - is this the same for Java?
When I tried to return a DOM Document containing XML, I got an error saying "Unable to create JAXBContext", so I changed it to just returning a String array. However, getting content from that array is rather tedious. Does anyone have a better solution?
Thanks,
VeganSmarties
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当我实现 JAX-WS Web 服务时,我的所有返回类型都使用 JAXB 注释(@XmlElement,...)进行注释,并且它们也是可序列化的。编辑:这意味着任何类型都不起作用,您将必须围绕要返回的结构创建包装器。
When I was implementing JAX-WS web services, all my return types were annotated with JAXB annotations (@XmlElement, ...), and they also were Serializable. EDIT: which means just any type will not work, and you will have to create wrappers around structures you want to return.