javaweb-serviceswsdljax-wsjava2wsdl

Getting rid of <arg0>


I have Java WebService code in my eclipse. I have used @WebService @Webmethod, @XmlElements, @XmlType, @XmlAccessorType

Now I am generating wsdl using java2ws command from cxf framework. Here is the command

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

my wsdl file contqins agr0 as name which I do not want because when I am importing it to SoapUI. It is adding tag around the field.

Here is wsdl part with arg0

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

Here is the request object which is generated in 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>

If I remove tag I get this response:

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

I do not want to keep arg0 in the request XML


Solution

  • I just fixed it after some research of my own code. The only thing which is required to change <arg0> is that we need to used @WebParam annotation to declare custome name instead of "arg0".

    For example:

    my service name is getEmpDetail and EmpID is the input parameter to the service then here is the declaration required in the service impl class:

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

    after generatingfrom WSDL the request XML will look like below

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