Following the last post of this discussion, I've created a client to send a request to a SOAP RPC web service.
First of all I've created the XML Project file through this method:
public static void runSoap() throws Exception {
String projectFile = "C:/Test/TestProjectA-soapui-project.xml";
SoapUI.setSoapUICore(new StandaloneSoapUICore(true));
WsdlProject project = new WsdlProject(projectFile);
int c = project.getInterfaceCount();
for(int i=0;i<c;i++) {
WsdlInterface wsdl = (WsdlInterface) project.getInterfaceAt(i);
String soapVersion = wsdl.getSoapVersion().toString();
System.out.println("The SOAP version ="+soapVersion);
System.out.println("The binding name = "+wsdl.getBindingName());
int opc = wsdl.getOperationCount();
System.out.println("Operation count ="+opc);
String result="";
for(int j=0;j<opc;j++){
WsdlOperation op = wsdl.getOperationAt(j);
String opName = op.getName();
System.out.println("OPERATION:"+opName);
WsdlRequest req = op.getRequestByName("Req_"+soapVersion+"_"+opName);
req.setEndpoint("<my_WSDL_ENDPOINT>");
WsdlSubmitContext wsdlSubmitContext = new WsdlSubmitContext(req);
WsdlSubmit<?> submit = (WsdlSubmit<?>) req.submit(wsdlSubmitContext, false);
Response response = submit.getResponse();
result = response.getContentAsString();
System.out.println("The result ="+result);
}
}
After the xml creation I've launched the next code to try to call the login operation. This operations has 3 parts:
- user
- pwd
- keycartella
This is the code to send the request, but I don't know the method to call to assign the value to the 3 message parts above:
public static void sendRequest() throws XmlException, IOException, SoapUIException, SubmitException{
String projectFile = "C:/Test/TestProjectA-soapui-project.xml";
WsdlProject project = new WsdlProject(projectFile);
WsdlInterface wsdl = (WsdlInterface) project.getInterfaceAt(0);
String soapVersion = wsdl.getSoapVersion().toString();
WsdlOperation op =
(WsdlOperation) wsdl.getOperationByName( "login" );
WsdlRequest req = op.getRequestByName("Req_"+soapVersion+"_"+ "login");
req.setEndpoint("<my_WSDL_ENDPOINT>");
WsdlSubmitContext wsdlSubmitContext = new WsdlSubmitContext(req);
WsdlSubmit<?> submit = (WsdlSubmit<?>) req.submit(wsdlSubmitContext, false);
Response response = submit.getResponse();
String result = response.getContentAsString();
System.out.println("The result ="+result);
}
To be clear the SOAP envelope body is:
<soapenv:Body>
<urn:login soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<user xsi:type="xsd:string">?</user>
<pwd xsi:type="xsd:string">?</pwd>
<keycartella xsi:type="xsd:string">?</keycartella>
</urn:login>
I'd like to substitute the default "?" with a real value via Java code, not changing the XML file.