我正在使用改装肥皂服务,我得到了Element' Body'没有..错误。我对肥皂不好:) 这是我的回复和我的对象
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<EncryptResponse xmlns="http://tempuri.org/">
<EncryptResult>%%UmVxdWVzdElzVmFsaWQyOTowMToyMDE1IDE2OjMx%%</EncryptResult>
</EncryptResponse>
</soap:Body>
</soap:Envelope>
EncryptResponseEnvelope
@Root(name = "soap:Envelope")
@NamespaceList({
@Namespace( prefix = "xsi", reference = "http://www.w3.org/2001/XMLSchema-instance"),
@Namespace( prefix = "xsd", reference = "http://www.w3.org/2001/XMLSchema"),
@Namespace( prefix = "soap", reference = "http://schemas.xmlsoap.org/soap/envelope/")
})
public class EncryptResponseEnvelope {
@Element(name = "soap:Body", required = false)
private EncryptResponseBody body;
public EncryptResponseBody getBody() {
return body;
}
public void setBody(EncryptResponseBody body) {
this.body = body;
}
}
EncryptResponseBody
@Root(name = "soap:Body", strict = false)
public class EncryptResponseBody {
@Element(name = "EncryptResponse", required = false)
private EncryptResponseData encryptResponseData;
public EncryptResponseData getEncryptResponseData() {
return encryptResponseData;
}
public void setEncryptResponseData(EncryptResponseData encryptResponseData) {
this.encryptResponseData = encryptResponseData;
}
}
EncryptResponseData
@Root(name = "EncryptResponse", strict = false)
@Namespace(reference = "http://tempuri.org/")
public class EncryptResponseData {
@Element(name = "EncryptResult", required = false)
private String encryptResult;
public String getEncryptResult() {
return encryptResult;
}
public void setEncryptResult(String encryptResult) {
this.encryptResult = encryptResult;
}
}
这是我的错误:
org.simpleframework.xml.core.ElementException:Element&#39; Body&#39;才不是 在课堂上有一场比赛 com.package.chal.data.response.encrypt_response.EncryptResponseEnvelope 在第1行
我在哪里犯错?
答案 0 :(得分:2)
SOAP Envelope:
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Namespace;
import org.simpleframework.xml.NamespaceList;
import org.simpleframework.xml.Root;
@Root(name="soap:Envelope", strict=false)
@NamespaceList({
@Namespace(reference="http://schemas.xmlsoap.org/soap/envelope/", prefix="soap"),
@Namespace(reference="http://www.w3.org/2001/XMLSchema", prefix="xsd"),
@Namespace(reference="http://www.w3.org/2001/XMLSchema-instance", prefix="xsi")
})
public class Envelope {
@Element(name="Body")
private Body body;
public Body getBody() {
return body;
}
public void setBody(Body body) {
this.body = body;
}
}
SOAP Body:
import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementUnion;
import org.simpleframework.xml.Namespace;
import org.simpleframework.xml.Path;
import org.simpleframework.xml.Root;
@Root(strict = false)
@Namespace(reference = "http://schemas.xmlsoap.org/soap/envelope/", prefix = "soap")
public class Body {
// By using ElementUnion, you can re-use the Envelope/Body classes for
// a variety of messages...
@ElementUnion({
// @Element(name="login", type=Login.class),
@Element(name = "EncryptResponse", type = EncryptResponse.class) })
public Object payload;
}
SOAP负载:
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Namespace;
import org.simpleframework.xml.Root;
@Root
@Namespace(reference="http://tempuri.org/")
public class EncryptResponse {
@Element
public String EncryptResult;
}
我测试了这个解决方案,它适用于序列化/反序列化。
答案 1 :(得分:0)
根据克里斯的回答,我遇到了同样的错误 我只将我的身体类别元素名称更改为;
来自
@Element(name = "soap:Body", required = false)
到
@Element(name="Body")
然后它现在可以正常工作。