How SOAP Request with HTTP authentication will look like ?

Balaji D Loganathan

1 min read

This is a soap request sent from Java Servlet to call the Calucator Webserive.
The below snippet was taken using TCPtrace.

Server: ServletExec, IIS, Apache Axis.
Client: Java Servlet. JDK 1.4


Raw HTTP with Authentication


POST /axis14/Calculator.jws?wsdl HTTP/1.0
Content-Type: text/xml; charset=utf-8
Accept: application/soap+xml, application/dime, multipart/related, text/*
User-Agent: Axis/1.4
Host: localhost:8090
Cache-Control: no-cache
Pragma: no-cache
SOAPAction: “”
Content-Length: 400
Authorization: Basic YmFsYWppZGw6bG9nc2FuYmFs

<?xml version=”1.0″ encoding=”UTF-8″?>
<soapenv:Envelope xmlns:soapenv=”http://schemas.xmlsoap.org/soap/envelope/”
  xmlns:xsd=”http://www.w3.org/2001/XMLSchema” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”>
<soapenv:Body>
 <add soapenv:encodingStyle=”http://schemas.xmlsoap.org/soap/encoding/”>
 <op1 xsi:type=”xsd:int”>5</op1>
 <op2 xsi:type=”xsd:int”>5</op2>
 </add>
</soapenv:Body>
</soapenv:Envelope>
 

Java Servlet based client code snippet


try {
 String endpoint = “http://localhost:8090/axis14/Calculator.jws?wsdl”;

 Integer i1 = new Integer(5);
 Integer i2 = new Integer(975);

 Service service = new Service();
 Call call = (Call) service.createCall();
 call.setTargetEndpointAddress( new java.net.URL(endpoint) );
 call.setUsername(“balajidl”);
 call.setPassword(“somepassword”);
 call.setOperationName( “add” );
 call.addParameter( “op1”, XMLType.XSD_INT, ParameterMode.IN );
 call.addParameter( “op2”, XMLType.XSD_INT, ParameterMode.IN );
 call.setReturnType( XMLType.XSD_INT );

 Integer ret = (Integer) call.invoke( new Object [] { i1, i2 });

 out.println(“Got result : ” + ret);
} catch (Exception e) {
 System.err.println(e.toString());
}

Raw HTTP without authentication message


POST /axis14/Calculator.jws?wsdl HTTP/1.0
Content-Type: text/xml; charset=utf-8
Accept: application/soap+xml, application/dime, multipart/related, text/*
User-Agent: Axis/1.4
Host: localhost:8090
Cache-Control: no-cache
Pragma: no-cache
SOAPAction: “”
Content-Length: 400

<?xml version=”1.0″ encoding=”UTF-8″?>
<soapenv:Envelope xmlns:soapenv=”http://schemas.xmlsoap.org/soap/envelope/”
  xmlns:xsd=”http://www.w3.org/2001/XMLSchema” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”>
<soapenv:Body>
 <add soapenv:encodingStyle=”http://schemas.xmlsoap.org/soap/encoding/”>
 <op1 xsi:type=”xsd:int”>5</op1>
 <op2 xsi:type=”xsd:int”>5</op2>
 </add>
</soapenv:Body>
</soapenv:Envelope>
 

Related posts:

Leave a Reply

Your email address will not be published. Required fields are marked *