如何使用 JBossWS 3.1.2 将 HashMap 作为 @WebParam
我正在尝试使用 JBossWS 3.1.2 开发一个 Web 服务,该服务将 HashMap 作为其参数之一。我正在使用这个版本的 JBossWS,因为它是随我正在使用的 JBoss 版本一起分发的。我使用 wsprovide 生成 WSDL,并使用 wsconsume 创建 WS 客户端存根。
我的 WebService 的简化版本是:
@WebService(targetNamespace = "http://localhost/ping", serviceName = "Ping")
@SOAPBinding(style = SOAPBinding.Style.RPC)
public class Ping {
@WebMethod
@WebResult(name="result")
public String ping(@WebParam(name="arguments") HashMap arguments) {
return "pong";
}
}
wsprovide 创建的 WSDL 包含:
<types>
<xs:schema targetNamespace='http://localhost/ping' version='1.0' xmlns:tns='http://localhost/ping' xmlns:xs='http://www.w3.org/2001/XMLSchema'>
<xs:complexType name='hashMap'>
<xs:complexContent>
<xs:extension base='tns:abstractMap'>
<xs:sequence/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType abstract='true' name='abstractMap'>
<xs:sequence/>
</xs:complexType>
</xs:schema>
</types>
生成的客户端代码包含一个空抽象类 AbstractMap.java 和一个空类 HashMap。
我本希望生成类似于以下内容的 WSDL:
<complexType>
<sequence>
<element name="key" type="anyType" />
<element name="value" type="anyType" />
</sequence>
</complexType>
我还尝试使用自定义类 (ParameterMap) 包装 HashMap,但只是得到了更多相同的内容。
还有我没有看到的下一步吗?我是否遗漏了什么,或者这是使用 JBossWS 开发 Web 服务的自下而上方法的限制?
I am trying to develop a web service with JBossWS 3.1.2 that has a HashMap as one of its arguments. I am using this version of JBossWS because that is what is distributed with the version of JBoss that I am using. I am using wsprovide to generate the WSDL and wsconsume to create WS client stubs.
A simplified version of my WebService is:
@WebService(targetNamespace = "http://localhost/ping", serviceName = "Ping")
@SOAPBinding(style = SOAPBinding.Style.RPC)
public class Ping {
@WebMethod
@WebResult(name="result")
public String ping(@WebParam(name="arguments") HashMap arguments) {
return "pong";
}
}
The WSDL created by wsprovide contains:
<types>
<xs:schema targetNamespace='http://localhost/ping' version='1.0' xmlns:tns='http://localhost/ping' xmlns:xs='http://www.w3.org/2001/XMLSchema'>
<xs:complexType name='hashMap'>
<xs:complexContent>
<xs:extension base='tns:abstractMap'>
<xs:sequence/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType abstract='true' name='abstractMap'>
<xs:sequence/>
</xs:complexType>
</xs:schema>
</types>
The generated client code contains an empty abstract class AbstractMap.java and an empty class HashMap.
I would have expected WSDL similar to the following to have been generated:
<complexType>
<sequence>
<element name="key" type="anyType" />
<element name="value" type="anyType" />
</sequence>
</complexType>
I also tried wrapping HashMap with a custom class (ParameterMap) but just got more of the same.
Is there a next step that I'm not seeing? Am I missing something or is this a limitation to the bottom up approach to developing Web Services with JBossWS?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案在另一篇文章如何将数组作为值传递到 PHP Soapclient 请求中?
我从来没有想过研究 JAX-WS 解决方案的 PHP 问题...
HashMap 需要包装在另一个名为 HashMapWrapper.java(或其他)的 Java 类中。
需要修改 ping 方法调用以使用包装类而不是 HashMap:
这会生成适当的 WSDL,进而生成有用的 Java 存根。
The answer was in another post How can I pass in an array as a value into a PHP soapclient request?
I would have never thought to look into a PHP question for a JAX-WS solution...
The HashMap needs to be wrapped in another Java class called HashMapWrapper.java (or whatever).
The ping method call needs to be modified to use the wrapper class instead of HashMap:
This generates appropriate WSDL which in turns generates useful Java stubs.