解析Soap服务使用Retrofit我正面临这样的异常(即)响应中类别包络模型中不匹配的身体模型

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了解析Soap服务使用Retrofit我正面临这样的异常(即)响应中类别包络模型中不匹配的身体模型相关的知识,希望对你有一定的参考价值。

解析Soap Services中的响应时使用Retrofit iam面临此异常。我的例外情况如下

  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>

VerifyMobileResEnvelopeModel

@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;
 }
}

VerifyMobileResBodyModel

@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;
 }
}

VerifyMobileResDataModel

@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());
        }
    });
}

我正面临一些解析问题。但得到了反响。在该方法中,它不会进入响应块,故障块被执行并且它会抛出此异常。找出问题很麻烦。我尝试了很多。请有人帮帮我。提前致谢。

我的代码中的响应。但它没有进入响应块

<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;  } }

以上是关于解析Soap服务使用Retrofit我正面临这样的异常(即)响应中类别包络模型中不匹配的身体模型的主要内容,如果未能解决你的问题,请参考以下文章

无法在HttpLoggingInterceptor Retrofit2.0上解析setLevel

使用 Retrofit 解析数组内的动态数组

如何在iphone中解析soap请求

使用 Retrofit 解析本地 JSON 文件中的文本

当列表的各个项目使用Retrofit和Gson的格式不同时,如何解析json列表?

无服务器框架 - 新变量解析器