Search code examples
javaweb-servicessoapwsdlsoapui

Extract data from soap service using java code


i am tring to extract response data from wsdl url using soapui java code. all are working good, but problem is in response.

in response i am getting ? instead of getting proper data.

Eclipse Console result

eclipse console result

but when i am tring to hit wsdl url using soapui it is working fine.enter image description here

check my code

package src.com;

import com.eviware.soapui.impl.wsdl.WsdlInterface;
import com.eviware.soapui.impl.wsdl.WsdlOperation;
import com.eviware.soapui.impl.wsdl.WsdlProject;
import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlImporter;
import com.eviware.soapui.model.iface.Operation;

public class Test {

    public static void main(String[] args) throws Exception {
        WsdlProject project = new WsdlProject();
        WsdlInterface[] wsdls = WsdlImporter.importWsdl(project, "http://localhost:8080/SoapService/services/TestService?wsdl");
        WsdlInterface wsdl = wsdls[0];
        for (Operation operation : wsdl.getOperationList()) {
            WsdlOperation wsdlOperation = (WsdlOperation) operation;
            System.out.println("Request:\n"+wsdlOperation.createRequest(true));
            System.out.println("\nResponse:\n"+wsdlOperation.createResponse(true));

        }
    }
}

Check Jars

enter image description here


Solution

  • Within the SoapUI application you are actually making a call out to the web service and getting a response. In your sample java code you are just generating a response XML from the WSDL file instead of actually calling out to the web service and it's defaulting any required values to have a ?. If you generate the same response within the SoapUI application you will see the same ? set for the findAllReturned element.

    You can use the java SoapUI's WSDLSubmit class to make a call out to the web service and get a response back.

    The answer to this linked question shows a code sample of how you would go about making an actual call out to the web service using the SoapUI java api: https://stackoverflow.com/a/14814524/8127149

    And this link has other examples of using the WSDLSubmit class: http://www.programcreek.com/java-api-examples/index.php?api=com.eviware.soapui.impl.wsdl.WsdlSubmit