我正在尝试使用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服务的自下而上方法的限制?
发布于 2011-01-12 01:13:17
答案就在另一篇文章How can I pass in an array as a value into a PHP soapclient request?中
我从来没有想过要研究JAX-WS解决方案的PHP问题...
HashMap需要包装在另一个名为HashMapWrapper.java (或其他任何类)的类中。
public class HashMapWrapper {
public HashMap<String, Object> parameters;
}ping方法调用需要修改为使用包装器类而不是HashMap:
public String ping(@WebParam(name="arguments") HashMapWrapper arguments) {这会生成适当的WSDL,而WSDL又会生成有用的Java存根。
https://stackoverflow.com/questions/4654423
复制相似问题