【问题标题】:Getting rid of <arg0>摆脱 <arg0>
【发布时间】:2014-05-05 14:39:04
【问题描述】:

我的 Eclipse 中有 Java WebService 代码。我用过@WebService @Webmethod、@XmlElements、@XmlType、@XmlAccessorType

现在我正在使用 cxf 框架中的 java2ws 命令生成 wsdl。这是命令

F:\....\code\java2wsdl>java2ws -o CustomerVxRR.wsdl -d <myOutputDir> -wsdl -cp <myClassesFolder> <ServiceImpl class>

我的 wsdl 文件 contqins agr0 作为我不想要的名称,因为当我将它导入 SoapUI 时。它在字段周围添加标签。

这是带有 arg0 的 wsdl 部分

<xs:schema ..... >
<xs:complexType name="myServiceMethodName">
<xs:sequence>
<xs:element minOccurs="0" name="arg0" type="tns:ServiceInputClassName"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="ServiceInputClassName">
<xs:sequence>
<xs:element minOccurs="0" name="EmpID" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xz:schema>

这是在 SOAPUI 中生成的请求对象

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cus="http://customeroffer.manage.ws.hello.my.com/">
   <soapenv:Header/>
   <soapenv:Body>
      <cus:myServiceMethodName>
         <!--Optional:-->
         <arg0>
            <EmpID >123456</EmpID>
         </arg0>
      </cus:myServiceMethodName>
   </soapenv:Body>
</soapenv:Envelope>

如果我删除标签,我会收到以下回复:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <soap:Fault>
         <faultcode>soap:Client</faultcode>
         <faultstring>Unmarshalling Error: unexpected element (uri:"", local:"EmpID"). Expected elements are &lt;{}empid></faultstring>
      </soap:Fault>
   </soap:Body>
</soap:Envelope>

我不想在请求 XML 中保留 arg0

【问题讨论】:

    标签: java web-services wsdl jax-ws java2wsdl


    【解决方案1】:

    在对自己的代码进行一些研究后,我刚刚修复了它。唯一需要更改&lt;arg0&gt; 的是我们需要使用@WebParam 注释来声明客户名称而不是“arg0”。

    例如:

    我的服务名称是 getEmpDetail 并且 EmpID 是服务的输入参数,那么这里是服务 impl 类中所需的声明:

    public Emp getEmpDetail(@WebParam(name="EmpDetail") String EmpId)
    

    从 WSDL 生成后,请求 XML 将如下所示

    <ns:getEmpDetail>
    <EmpDetail>
    <EmdID>?</EmpID>
    </EmpDetail>
    <ns:getEmpDetail>
    

    【讨论】:

    • 除了上面的内容,你可能需要确保接口类有@WebParam,如果你有的话。
    猜你喜欢
    • 2010-11-03
    • 2012-08-05
    • 1970-01-01
    • 1970-01-01
    • 2011-01-23
    • 2017-02-03
    • 2015-11-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多