Search code examples
javasoapsoapuisoap-client

SOAP XML request for initializing an Object value in JAVA Class


I am having the below JAVA Class :

@WebService()
@SOAPBinding(style = Style.DOCUMENT, use = Use.LITERAL, parameterStyle = ParameterStyle.BARE)
public class Demo extends JaxWsWebService
{
@WebMethod(operationName = "createMethod")
@WebResult(targetNamespace = "xyz.com/")
@RequestWrapper(localName = "Testing", targetNamespace = "xyz.com/", className = "com.Test")
public void createMethod(Testing testingData) throws SOAPException {

    System.out.println(" createMethod service --- xId = " + testingData.getXId() "); // xId is coming as NULL
    System.out.println(" createMethod service --- name = " + testingData.getName() "); // name is coming as NULL
}
}

Now I am calling the above JAVA method using my SOAP XML Request which is below :

<x:Envelope xmlns:x="http://schemas.xmlsoap.org/soap/envelope/" xmlns:NS1="xyz.com/">
<x:Header/>
<x:Body>
<NS1:createMethod>
<NS1:Testing>
    <xId>12345</xId>
    <name>abcd</name>
</NS1:Testing>
</NS1:createMethod>
</x:Body>
</x:Envelope>

Now, when I am calling the SOAP request using the SOAP client, the call is successful and is going inside the JAVA method but the main issue is the "testingData" instance of "Testing" class is not getting initialized.

Due to this, I am getting the value of 'xId' and 'name' variable as NULL in my JAVA method. Any suggestions on this would be helpful it looks like I am making mistake in my SOAP request calling but unable to figure it out.

Please suggest. TIA


Solution

  • Got the place where I was going wrong :

    <x:Envelope xmlns:x="http://schemas.xmlsoap.org/soap/envelope/" xmlns:NS1="xyz.com/">
    <x:Header/>
    <x:Body>
    <NS1:createMethod>
        <xId>12345</xId>
        <name>abcd</name>
    </NS1:createMethod>
    </x:Body>
    </x:Envelope>
    

    In the XML request , I removed the <NS1:Testing> starting and ending </NS1:Testing> tags and finally it started working for me.