I'm very new to soap and i found an example of how to do a request here: Working Soap client example
Using a chrome plugin i've managed to find a soap query string that works which is:
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<GetMyProjectCharges xmlns="http://company.IWWeb.Data.Service.ProjectCharges">
<Employee>26270</Employee>
<FiscalYear>2015</FiscalYear>
<ApiKey>APIKEY</ApiKey>
<AppName>APPNAME</AppName>
</GetMyProjectCharges>
</Body>
</Envelope>
So trying the code posted from the stack post I wrote:
private static SOAPMessage createSOAPRequest() throws Exception {
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
String serverURI = "http://schemas.xmlsoap.org/soap/envelope/";
// SOAP Envelope
SOAPEnvelope envelope = soapPart.getEnvelope();
/*
Constructed SOAP Request Message:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:example="http://ws.cdyne.com/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<example:VerifyEmail>
<example:email>mutantninja@gmail.com</example:email>
<example:LicenseKey>123</example:LicenseKey>
</example:VerifyEmail>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
*/
// SOAP Body
SOAPBody soapBody = envelope.getBody();
SOAPElement soapBodyElem = //soapBody.addChildElement("GetMyProjectCharges");
soapBody.addChildElement("GetMyProjectCharges", "", "http://company.IWWeb.Data.Service.ProjectCharges");
SOAPElement soapBodyEmployee = soapBodyElem.addChildElement("Employee").addTextNode("26270");
SOAPElement soapBodyFiscalYear = soapBodyElem.addChildElement("FiscalYear").addTextNode("2015");
SOAPElement soapBodyAPIKey = soapBodyElem.addChildElement("ApiKey").addTextNode("APIKEY");
SOAPElement soapBodyAppName = soapBodyElem.addChildElement("AppName").addTextNode("APPNAME");
MimeHeaders headers = soapMessage.getMimeHeaders();
headers.addHeader("SOAPAction", serverURI + "GetMyProjectCharges");
soapMessage.saveChanges();
/* Print the request message */
System.out.print("Request SOAP Message:");
soapMessage.writeTo(System.out);
System.out.println();
return soapMessage;
}
However I'm ending up with the following soap request code:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<GetMyProjectCharges xmlns="http://company.IWWeb.Data.Service.ProjectCharges">
<Employee>26270</Employee>
<FiscalYear>2015</FiscalYear>
<ApiKey>APIKEY</ApiKey>
<AppName>APPNAME</AppName>
</GetMyProjectCharges>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Which the server doesn't seem to happy about. Is there an easy way to modify what i'm doing to get a query string closer to what i want?