我有第三方web服务,我使用wsimport生成客户端。每次对web服务的调用都会成功完成,但我返回的响应对象将其所有字段设置为null。监视网络我可以看到,响应消息中的所有XML元素都有值,因此对象应该包含非空数据。此外,使用旧的axis1生成的相同服务的客户端使用相同的数据调用将返回非空的响应。任何想法发生了什么? (如果它有什么区别,我使用MOXy的JAXB实现)。我的jax-ws web服务客户端只返回空对象
更新:我已经能够缩小它。 wsdl在其自己的名称空间中定义对象,如http://www.acme.com/ws
。我从服务中得到的响应是
<?xml version="1.0" encoding="UTF-8"?>
... SOAP envelope ...
<ns1:opINFOWLResponse xmlns:ns1="http://www.acme.com/ws"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ns1:responseINFOWL xsi:type="ns1:responseINFOWL">
<result>6003</result>
<ndserr/>
<transid>61437594</transid>
<descriptionerr>BLAH.</descriptionerr>
</ns1:responseINFOWL>
</ns1:opINFOWLResponse>
... SOAP closing tags ...
,并解组到非空OpINFOWLResponse
围绕一个非空responseINFOWL
对象包装设置为空的所有字段。只是为了好玩,我试着写几行解组上面的代码(剥离SOAP开销后)
JAXBContext ctx = JAXBContext.newInstance(OpINFOWLResponse.class);
Unmarshaller u = ctx.createUnmarshaller();
OpINFOWLResponse o = (OpINFOWLResponse) u.unmarshal(new StringReader(theSnippetAbove));
ResponseINFOWL w = o.getResponseINFOWL();
,我也得到了相同的结果。如果我将上面的XML更改为
<?xml version="1.0" encoding="UTF-8"?>
<ns1:opINFOWLResponse xmlns:ns1="http://www.acme.com/ws"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ns1:responseINFOWL xsi:type="ns1:responseINFOWL">
<ns1:result>6003</ns1:result>
<ns1:ndserr/>
<ns1:transid>61437594</ns1:transid>
<ns1:descriptionerr>BLAH.</ns1:descriptionerr>
</ns1:responseINFOWL>
</ns1:opINFOWLResponse>
一切工作正常。游民。
更新(再次):与jaxb-RI和Moxy都具有相同的行为。仍然不知道什么是错的。
更新(9月9日):下面关于命名空间的限制条件是错的建议很有趣,但我认为的wsimport将正确的事情。无论如何,这是我的package-info.java
@XmlSchema(
namespace = "http://www.acme.com/ws",
elementFormDefault = XmlNsForm.QUALIFIED)
package it.sky.guidaTv.service.remote;
import javax.xml.bind.annotation.XmlSchema;
import javax.xml.bind.annotation.XmlNsForm;
,这是ResponseINFOWL
类
/*
* <p>Java class for responseINFOWL complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType name="responseINFOWL">
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="result" type="{http://www.w3.org/2001/XMLSchema}string"/>
* <element name="descriptionerr" type="{http://www.w3.org/2001/XMLSchema}string"/>
* <element name="transid" type="{http://www.w3.org/2001/XMLSchema}string"/>
* <element name="ndserr" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* <element name="wallet" type="{http://www.acme.com/ws}t_wallet" minOccurs="0"/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "responseINFOWL", propOrder = {
"result", "descriptionerr", "transid", "ndserr", "wallet" })
public class ResponseINFOWL {
@XmlElement(required = true)
protected String result;
@XmlElement(required = true)
protected String descriptionerr;
@XmlElement(required = true)
protected String transid;
protected String ndserr;
protected TWallet wallet;
// getters, setters and all.
}
我试着打了一下,在package-info
的命名空间,但仍然没有喜悦的相关部分。
你能提供消息和类的样本吗?这将有助于确定映射中不匹配的位置。 –
也许我可以发布适当的匿名wsdl文件和测试类,我的情况下的其他一切都是由wsimport生成的。有趣的是来自同一第三方的其他服务正常工作。 – agnul