JAVA
Implementation using SAAJ
package javatestapplication;
import javax.xml.soap.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;
import javax.xml.namespace.QName;
public class Main {
public static void main(String[] args) {
try
{
// Create SOAP Connection
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();
// Send SOAP Message to SOAP Server
String endpoint = "http://api.tbotechnology.in/HotelAPI_V7/HotelService.svc";
SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(), endpoint);
soapResponse.writeTo(System.out);
soapConnection.close();
} catch (Exception e) {
System.err.println("Error occurred while sending SOAP Request to Server");
e.printStackTrace();
}
}
private static SOAPMessage createSOAPRequest() throws Exception {
MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
String serverURI = "http://TekTravel/HotelBookingApi";
// SOAP Envelope
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("hot", serverURI);
// SOAP Header
SOAPHeader header = envelope.getHeader();
header.addNamespaceDeclaration("wsa", "http://www.w3.org/2005/08/addressing");
SOAPElement soapHeaderElem = header.addChildElement("Credentials", "hot");
soapHeaderElem.addAttribute(new QName("UserName"), "kuldeep");
soapHeaderElem.addAttribute(new QName("Password"), "54321");
SOAPElement soapHeaderElem1 = header.addChildElement("Action", "wsa");
soapHeaderElem1.addTextNode("http://TekTravel/HotelBookingApi/DestinationCityList");
SOAPElement soapHeaderElem2 = header.addChildElement("To", "wsa");
soapHeaderElem2.addTextNode("http://api.tbotechnology.in/HotelAPI_V7/HotelService.svc");
// SOAP Body
SOAPBody soapBody = envelope.getBody();
SOAPElement soapBodyElem = soapBody.addChildElement("DestinationCityListRequest", "hot");
SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("CountryCode", "hot");
soapBodyElem1.addTextNode("IN");
MimeHeaders headers = soapMessage.getMimeHeaders();
headers.addHeader("Content-Type", "application/soap+xml;charset=UTF-8");
soapMessage.saveChanges();
/* Print the request message */
System.out.print("Request SOAP Message = ");
soapMessage.writeTo(System.out);
System.out.println();
return soapMessage;
}
}