SOAP Web Service Tutorials - Herong's Tutorial Examples - Version 5.00, by Dr. Herong Yang

Using to Send SOAP Messages

This section describes steps to follow if you want to use the class to send out a SOAP XML message.

With both client side and server side testing programs ready to capture both request and response, I am ready to try to call Web services with the HttpURLConnection class in the package.

The HttpURLConnection class is a higher level communication tool comparing to the Socket class. It is relatively easy to use for calling a Web service:

1. The first step is to create HttpURLConnection object with the end point URL. Remember to use the openConnection() method on a URL object create a HttpURLConnection object, because HttpURLConnection offers no constructors.

   URL oURL = new URL("");
   HttpURLConnection con = (HttpURLConnection) oURL.openConnection();

2. Use the setRequestMethod() method to set the HTTP POST command:


3. Use the setRequestProperty() method to set header lines:

   con.setRequestProperty("Content-type", "text/xml; charset=utf-8");

4. Prepare the entire SOAP request XML message as a string by using a DOM object, reading from a file, or simply as:

   reqXML = "<?xml ...<soap:Envelope ...";

5. Then write the XML message to the connetion. reading from a file, or simply as:

   OutputStream reqStream = con.getOutputStream();

6. Finally read the SOAP response XML message from the connection reading from a file, or simply as:

   InputStream resStream = con.getInputStream();
   byte[] byteBuf = new byte[10240];
   int len =;

See the next tutorial for a sample HttpURLConnection program.

Last update: 2009.

Table of Contents

 About This Book

 Introduction to Web Service

 Introduction to SOAP (Simple Object Access Protocol)

 SOAP Message Structure

 SOAP Message Transmission and Processing

 SOAP Data Model

 SOAP Encoding

 SOAP RPC Presentation

 SOAP Properties Model

 SOAP Message Exchange Patterns

 SOAP HTTP Binding

 SOAP Perl Implementations

 SOAP PHP Implementations

 SOAP Java Implementations

 Perl SOAP::Lite - SOAP Server-Client Communication Module

 Perl Socket Test Program for HTTP and SOAP

 Perl SOAP::Lite for GetSpeech SOAP 1.1 Web Service

 Perl SOAP::Lite 0.710 for SOAP 1.2 Web Services

 Perl SOAP::Lite 0.710 for WSDL

 PHP SOAP Extension Client Programs

 PHP SOAP Extension Server Programs

Java Socket and HttpURLConnection for SOAP - Socket Client Testing Program - Socket Server Testing Program

 Capturing the HTTP Request from a Browser

 "read(byteBuf) = -1" Not Working

Using to Send SOAP Messages

 Using HttpURLConnection to Call GetSpeech SOAP 1.1

 Capturing HTTP Request Generated by the HttpURLConnection Class

 Calling GetSpeech SOAP 1.1 Web Service

 Using HttpURLConnection to Call GetSpeech SOAP 1.2

 Calling GetSpeech SOAP 1.2 Web Service

 SAAJ - SOAP with Attachments API for Java

 SoapUI - SOAP Web Service Testing Tool

 WS-Security - SOAP Message Security Extension

 WS-Security X.509 Certificate Token

 Web Services and SOAP Terminology


 PDF Printing Version

Using to Send SOAP Messages - Updated in 2014, by Dr. Herong Yang