我的 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 <{}empid></faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>
我不想在请求 XML 中保留 arg0
最佳答案
我只是在研究了自己的代码后才修复它。唯一需要改变的东西<arg0>
是我们需要使用 @WebParam
用于声明客户名称而不是“arg0”的注释。
例如:
我的服务名称是 getEmpDetail 并且 EmpID 是服务的输入参数然后这里是服务实现类中所需的声明:
public Emp getEmpDetail(@WebParam(name="EmpDetail") String EmpId)
从 WSDL 生成后,请求 XML 将如下所示
<ns:getEmpDetail>
<EmpDetail>
<EmdID>?</EmpID>
</EmpDetail>
<ns:getEmpDetail>
关于java - 摆脱 <arg0>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23475189/