SOAP消息无法解析为java对象
我有以下SOAP消息和生成的jaxb类 SOAP消息:SOAP消息无法解析为java对象,java,xml,soap,jaxb,Java,Xml,Soap,Jaxb,我有以下SOAP消息和生成的jaxb类 SOAP消息: <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soapenv:Body> <ns1:sendSmsResponse xmlns:ns1="http://www.csapi.org/schema/p
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns1:sendSmsResponse xmlns:ns1="http://www.csapi.org/schema/parlayx/sms/send/v2_2/local">
<result>100001200301111029065e4000141</result>
</ns1:sendSmsResponse>
</soapenv:Body>
</soapenv:Envelope>
但这会生成如下的解组异常
javax.xml.ws.soap.SOAPFaultException: Unmarshalling Error: unexpected element (uri:"http://www.csapi.org/schema/parlayx/sms/send/v2_2/local", local:"result"). Expected elements are <{}result>
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:161)
javax.xml.ws.soap.SOAPFaultException:解组错误:意外元素(uri:http://www.csapi.org/schema/parlayx/sms/send/v2_2/local“,本地:“结果”)。预期的要素是
位于org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:161)
但是如果我从
中删除ns1:
,它将进行解析。原因可能是什么?错误消息告诉您,它遇到了一个带有名称空间的结果元素,而预期的结果元素没有名称空间(中的“{}”表示没有名称空间)
必须通过namespace属性为JAXB指定名称空间:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "sendSmsResponse", propOrder = {
"result"
})
public class SendSmsResponse {
@XmlElement(required = true,namespace="http://www.csapi.org/schema/parlayx/sms/send/v2_2/local")
protected String result;
public String getResult() {
return result;
}
public void setResult(String value) {
this.result = value;
}
}
错误消息告诉您,它遇到了一个带有名称空间的结果元素,而预期的结果元素没有名称空间(中的“{}”表示没有名称空间) 必须通过namespace属性为JAXB指定名称空间:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "sendSmsResponse", propOrder = {
"result"
})
public class SendSmsResponse {
@XmlElement(required = true,namespace="http://www.csapi.org/schema/parlayx/sms/send/v2_2/local")
protected String result;
public String getResult() {
return result;
}
public void setResult(String value) {
this.result = value;
}
}