Hi I'm trying to call a SOAP Api from java, which tries to connect using tenantid, username, password, roles.
package com.virima.test;
import javax.xml.soap.*;
public class SOAPClient {
public static void main(String args[]) {
String soapEndpointUrl = "https://virimadev.trysaasit.com/ServiceAPI/FRSHEATIntegration.asmx";
String soapAction = "SaaS.Services/Connect";
callSoapWebService(soapEndpointUrl, soapAction);
}
private static void createSoapEnvelope(SOAPMessage soapMessage) throws SOAPException {
SOAPPart soapPart = soapMessage.getSOAPPart();
String myNamespace = "ns";
String myNamespaceURI = "SaaS.Services";
// SOAP Envelope
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration(myNamespace, myNamespaceURI);
// SOAP Body
SOAPBody soapBody = envelope.getBody();
SOAPElement soapBodyElem = soapBody.addChildElement("tenantId", myNamespace);
soapBodyElem.addTextNode("virimadev.trysaasit.com");
SOAPElement soapBodyElem1 = soapBody.addChildElement("userName", myNamespace);
soapBodyElem1.addTextNode("Alan.Taylor");
SOAPElement soapBodyElem2 = soapBody.addChildElement("userName", myNamespace);
soapBodyElem2.addTextNode("password");
SOAPElement soapBodyElem3 = soapBody.addChildElement("role", myNamespace);
soapBodyElem3.addTextNode("Admin");
}
private static void callSoapWebService(String soapEndpointUrl, String soapAction) {
try {
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();
// Send SOAP Message to SOAP Server
SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(soapAction), soapEndpointUrl);
// Print the SOAP Response
System.out.println("Response SOAP Message:");
soapResponse.writeTo(System.out);
System.out.println();
soapConnection.close();
} catch (Exception e) {
System.err.println("\nError occurred while sending SOAP Request to Server!\nMake sure you have the correct endpoint URL and SOAPAction!\n");
e.printStackTrace();
}
}
private static SOAPMessage createSOAPRequest(String soapAction) throws Exception {
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
createSoapEnvelope(soapMessage);
MimeHeaders headers = soapMessage.getMimeHeaders();
headers.addHeader("SOAPAction", soapAction);
soapMessage.saveChanges();
/* Print the request message, just for debugging purposes */
System.out.println("Request SOAP Message:");
soapMessage.writeTo(System.out);
System.out.println("\n");
return soapMessage;
}
}
But I'm getting the following error
Request SOAP Message:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="SaaS.Services"><SOAP-ENV:Header/><SOAP-ENV:Body><ns:tenantId>https://virimadev.trysaasit.com</ns:tenantId><ns:userName>Alan.Taylor</ns:userName><ns:userName>Manage</ns:userName><ns:role>Admin</ns:role></SOAP-ENV:Body></SOAP-ENV:Envelope>
I'm geting response with following error
Unhandled system exception: System.Web.Services.Protocols.SoapException: Server was unable to process request. ---&amp;gt; System.ArgumentNullException: CacheKey constructor tenantId-argument cannot be null-or-empty.
Parameter name: tenantId
I'm passing tenantId, but still it is saying parameter tenantId cant be null. Is there anything I'm missing.
myNamespaceURI?"SaaS.Services"doesn't look like URI at all.soapBody.addChildElement("tenantId", myNamespace)withsoapBody.addAttribute("tenantId", myNamespace)