SOAP XML request for initializing an Object value in JAVA Class

时间:2019-04-08 13:04:52

标签: java soap soapui soap-client

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

1 个答案:

答案 0 :(得分:0)

找到我要出问题的地方:

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

在XML请求中,我删除了<NS1:Testing>开头和结尾的</NS1:Testing>标签,最后它开始为我工作。