The Holy Java

Building the right thing, building it right, fast

Sending a SOAP request to a Web Service via URLConnection

Posted by Jakub Holý on May 25, 2006

You may want to test you web service by sending it a manually composed request and reading the XML returned. Here’s how to do it (e.g. using BeanShell in jEdit):

The SOAP request

<?xml version="1.0" encoding="utf-16"?>
<soap:Envelope xmlns:soap="" xmlns:xsi="" xmlns:xsd="">
    <getUserByEmail xmlns="">

The Java code

String soapXml =   // jEdit: = buffer.getText(0,buffer.getLength()) url = new"http://localhost:9081/myServiceWAR/services/MyService"); conn = url.openConnection();
// Set the necessary header fields
conn.setRequestProperty("SOAPAction", "http://localhost:9081/myServiceWAR/services/MyService");
// Send the request wr = new;
// Read the response rd = new;
String line;
while ((line = rd.readLine()) != null) { System.out.println(line); /*jEdit: print(line); */ }

2 Responses to “Sending a SOAP request to a Web Service via URLConnection”

  1. Great tip! This is a very usefull way of debugging an existing service endpoint when you don’t have your client application prepared.

  2. mukesh said

    Use SOAPUI

Sorry, the comment form is closed at this time.

%d bloggers like this: