java 生成 Web 服务客户端时 Apache 意外子元素异常

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10113395/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 23:40:49  来源:igfitidea点击:

Apache Unexpected subelement exception while generating a webservice client

javaweb-servicesexceptionaxis2

提问by martin s

I'm trying to generate a webservice client with wsdl2java from axis2 (version 1.6.1).

我正在尝试使用axis2(版本1.6.1)中的wsdl2java 生成一个Web 服务客户端。

./wsdl2java.sh -uri http://www.ncbi.nlm.nih.gov/entrez/eutils/soap/v2.0/efetch_snp.wsdl

When I call this service, I get an Exception.

当我调用此服务时,出现异常。

org.apache.axis2.AxisFault: org.apache.axis2.databinding.ADBException: Unexpected subelement {http://www.ncbi.nlm.nih.gov/soap/eutils/efetch_snp}Rs

org.apache.axis2.AxisFault: org.apache.axis2.databinding.ADBException: Unexpected subelement {http://www.ncbi.nlm.nih.gov/soap/eutils/efetch_snp}Rs

    try {
        EFetchSnpServiceStub fetchService = new EFetchSnpServiceStub();
        EFetchSnpServiceStub.EFetchRequest reqIdSnp = new EFetchSnpServiceStub.EFetchRequest();
        reqIdSnp.setId("193925233");
        EFetchSnpServiceStub.EFetchResult resIdSnp = fetchService.run_eFetch(reqIdSnp);
    } catch (Exception e) {
        System.out.println(e.toString());
    }   

With soaptesthowever I can see the Rs Tag in the result.

但是,使用soaptest,我可以在结果中看到Rs 标签。

<Rs rsId="193925233" snpClass="snp" snpType="notwithdrawn" molType="genomic" bitField="050000000005000000000100" taxId="3702">

How can I fix this exception? The WSDL is not under my control.

我该如何解决这个异常?WSDL 不在我的控制之下。

回答by shashankaholic

Unexpected subelementerror mostly occur in Axis2 in ADB databinding type. When the sequence of tags coming in SOAP response is not same as that of attributes in java class formed from wsdl.

意外的子元素错误主要发生在 ADB 数据绑定类型的 Axis2 中。当 SOAP 响应中的标签序列与 wsdl 形成的 java 类中的属性序列不同时。

For example,

例如,

If response or request XML must have a, b, c elements in a sequence and actual XML has a, d, c elements in the sequence, then Axis2 would complain saying that it received an Unexpected element named d.

如果响应或请求 XML 必须在一个序列中包含 a、b、c 元素,而实际的 XML 在序列中包含 a、d、c 元素,那么 Axis2 会抱怨说它收到了一个名为 d 的 Unexpected 元素。

It can be resolved by changing the sequence of tags in wsdl.

可以通过更改 wsdl 中的标签顺序来解决。

Note : If this is not the case, check here for other reasons

注意:如果不是这种情况,请在此处查看其他原因

回答by Ben

I just had the same problem with NCBI eutils and solved it by editing the wsdl file and then regenerating the client classes locally. I used soaptest as you did to see exactly what it was expecting and then made them match up. In my case, they were missing the element named "DbBuild" in their DbInfoType object.

我刚刚在 NCBI eutils 上遇到了同样的问题,并通过编辑 wsdl 文件然后在本地重新生成客户端类来解决它。我像你一样使用了soaptest来准确地看到它的预期,然后让它们匹配。就我而言,他们在 DbInfoType 对象中缺少名为“DbBuild”的元素。