gpt4 book ai didi

java - 解析 Soap Service 对 Retrofit 的使用我在响应中的类信封模型中面临这样的异常(即)不匹配的主体模型

转载 作者:太空宇宙 更新时间:2023-11-03 10:37:04 28 4
gpt4 key购买 nike

在使用 Retrofit 的 Soap Services 中解析响应时,我遇到了这个异常。我的异常如下

  Failure: org.simpleframework.xml.core.ElementException: Element 'Body' does not have a match in class org.cainfo.arun.model.response.VerifyMobileResEnvelopeModel at line 1

这是我的请求和回复

我的要求

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://webservice.router.ees.com/">
<soapenv:Header/>
<soapenv:Body>
<web:verifyMobile>
<arg0>12345678</arg0>
</web:verifyMobile>
</soapenv:Body>
</soapenv:Envelope>

我的回应

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns1:verifyMobileResponse xmlns:ns1="http://webservice.router.ees.com/">
<return>name</return>
</ns1:verifyMobileResponse>
</soap:Body>
</soap:Envelope>

验证移动资源包络模型

@Root(name = "soap:Envelope")
@Namespace( prefix = "soap", reference = "http://schemas.xmlsoap.org/soap/envelope/")
public class VerifyMobileResEnvelopeModel {
@Element(name = "soap:Body", required = false)
private VerifyMobileResBodyModel verifyMobileResBodyModel;

public VerifyMobileResBodyModel getVerifyMobileResBodyModel() {
return verifyMobileResBodyModel;
}

public void setBody(VerifyMobileResBodyModel verifyMobileResBodyModel) {
this.verifyMobileResBodyModel = verifyMobileResBodyModel;
}
}

验证MobileResBodyModel

@Root(name = "soap:Body", strict = false)
public class VerifyMobileResBodyModel {
@Element(name = "ns1:verifyMobileResponse", required = false)
@Namespace(prefix = "ns1", reference = "http://webservice.router.ees.com/")
private VerifyMobileResDataModel verifyMobileResModel;

public VerifyMobileResDataModel getVerifyMobileResModel() {
return verifyMobileResModel;
}

public void setVerifyMobileResModel(VerifyMobileResDataModel verifyMobileResModel) {
this.verifyMobileResModel = verifyMobileResModel;
}
}

验证移动资源数据模型

@Root(name = "ns1:verifyMobileResponse", strict = false)
@Namespace(prefix = "ns1", reference = "http://webservice.router.ees.com/")
public class VerifyMobileResDataModel {
@Element(name = "return", required = false)
private String customerName;

public String getCustomerName() {
return customerName;
}

public void setCustomerName(String customerName) {
this.customerName = customerName;
}
}

方法

public void getResponse() {
VerifyMobileRqstDataModel mVerifyMobileRqstDataModel = new VerifyMobileRqstDataModel();
mVerifyMobileRqstDataModel.phoneNo = mobileNo;

VerifyMobileRqstBodyModel mVerifyMobileRqstBodyModel = new VerifyMobileRqstBodyModel();
mVerifyMobileRqstBodyModel.verifyMobileRqstDataModel = mVerifyMobileRqstDataModel;

VerifyMobileRqstEnvelopeModel mVerifyMobileRqstEnvelopeModel = new VerifyMobileRqstEnvelopeModel();
mVerifyMobileRqstEnvelopeModel.verifyMobileRqstBodyModel = mVerifyMobileRqstBodyModel;

Call<VerifyMobileResEnvelopeModel> call = webService.rqstVerifyMobileNo(mVerifyMobileRqstEnvelopeModel);
call.enqueue(new Callback<VerifyMobileResEnvelopeModel>() {
@Override
public void onResponse(Call<VerifyMobileResEnvelopeModel> call, Response<VerifyMobileResEnvelopeModel> response) {
if (response.isSuccessful() && response.body() != null) {
// String customerName = response.body().verifyMobileResBodyModel.verifyMobileResModel.customerName;
String customerName = response.body().getBody().getVerifyMobileResModel().getCustomerName();
Log.i("CustomerName", customerName);

}
}

@Override
public void onFailure(Call<VerifyMobileResEnvelopeModel> call, Throwable t) {
Log.e("Failure", t.getMessage());
}
});
}

我遇到了一些解析问题。但得到回应。在它不进入响应 block 的方法中,执行失败 block 并抛出此异常。找出问题很麻烦。我试了很多。请任何人帮助我。提前致谢。

在我的代码中响应。但是它没有进入响应 block

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">   
<soap:Body>
<ns1:verifyMobileResponse xmlns:ns1="http://webservice.router.ees.com/">
<return>Ramesh</return>
</ns1:verifyMobileResponse>
</soap:Body>
</soap:Envelope>

最佳答案

虽然为时已晚,但这可能会帮助像我这样可怜的人,我也遇到过类似的问题。尝试在 ResponseBody 的根标签中设置“strict = false”,如下所示

@Root(name = "soap:Envelope", strict = false) 
@Namespace( prefix = "soap", reference = "http://schemas.xmlsoap.org/soap/envelope/")
public class VerifyMobileResEnvelopeModel { @Element(name = "soap:Body", required = false)
private VerifyMobileResBodyModel verifyMobileResBodyModel;

public VerifyMobileResBodyModel getVerifyMobileResBodyModel() {
return verifyMobileResBodyModel; }

public void setBody(VerifyMobileResBodyModel verifyMobileResBodyModel) {
this.verifyMobileResBodyModel = verifyMobileResBodyModel; } }

关于java - 解析 Soap Service 对 Retrofit 的使用我在响应中的类信封模型中面临这样的异常(即)不匹配的主体模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42060531/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com