Listing 3: The SoapTransport class provides SOAP Request/Response services by using two core classes: HTTPConection for HTTP communication and SoapCall for XML payload.
 
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.PrintWriter;

import java.net.UnknownHostException;


public class SoapTransport 
{
	
	// Holds SOAPAction header.
	private	String soapAction = "\"\"";
	
	// Holds body of request.
	private String body;
	
	// Holds complete request.
	private String request;
	
	// HttpConnection and SoapCall class objects.
	private HttpConnection connection;
	private SoapCall sc;
	

	// Constructor with URL and Port number arguments.
	public SoapTransport(String url, int port )
	throws UnknownHostException, IOException 
	{
		connection = new HttpConnection(url,port);
		sc = new SoapCall();
	}
	
	
	// Sets SOAPAction header header of Soap request.
	public void setSoapAction(String soapAction)
	{
		this.soapAction = soapAction;
	}//setSoapAction()
	
	
	// Takes request body as string 
	// and internally calls setBody method of SoapCall.
	public void setBody(String body)
	{
		sc.setBody(body);
		this.body=body;
	}//setBody()


  	// Returns Body of SOAP Envelope.
	public String getBody()
	{
		return sc.getCompleteSOAPRequest();
	}//getBody()
	
	
	// Constructs SOAP request and sends it.
	// Returns the received response as String.
	public String send()
	{
		String response = "";
		try
		{
			body = sc.getCompleteSOAPRequest();

			// Setting HTTP headers values.	
			connection.setRequestMethod ("POST");
		    connection.setContentType ("text/xml");
			connection.setContentLength (body.length());
			connection.setRequestProperty ("SOAPAction:"
			, soapAction);
			
			String headers = connection.getHeaders();
			request = new String(headers);
			
			// Getting XML payload from SoapCall	
			// and appending it with request.	
			request+= body;
			
			// Getting input/output streams from connection.
			PrintWriter out   = new 
			PrintWriter(connection.getOutputStream());
			BufferedReader in = new BufferedReader
			(newInputStreamReader
            (connection.getInputStream()));	
			
			// Sending request to output streams.
			out.println(request);
			out.flush();
			
			StringBuffer sc = new StringBuffer();
			String line = null;

			// Receiving respone	.
			while((line=in.readLine())!=null)
			{
				sc.append(line);
				sc.append("\r\n");
			}
			
			response = sc.toString();
			in.close();
			out.close();
		
		} catch(Exception e)	{ e.printStackTrace();	}

		// Returning response.
		return response.substring(response.indexOf("<"));
	}//send()	
	
}//class