我有第三方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