Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Web Services and the fly likes web service + java Client Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark " web service + java Client" Watch " web service + java Client" New topic
Author web service + java Client

madhup narain
Ranch Hand

Joined: Dec 14, 2004
Posts: 148
I am new to WEB SERVICES and basically need to use a java client for a WEB SERVICE in

I would like someone to help me out as to how i should proceed and be able to access the web service.


Money for nothing and Java for Free
Tim West
Ranch Hand

Joined: Mar 15, 2004
Posts: 539
The Web service will expose a WSDL, like any other. From this point, you can (mostly*) ignore the fact that the service is implemented in

Then, implement it like any other Web service. This recent thread had some links for this.


When accessing a Web service produced using a toolkit other than the one you're using, it's quite possible you'll run into difficulties/bugs/inconsistencies. There are some documented problems between Microsoft platforms and Java ones, such as Microsoft's use of 'Document/Literal Wrapped', which is non-standard. Googling with the appropriate terms will find a horde of relevant sites.
madhup narain
Ranch Hand

Joined: Dec 14, 2004
Posts: 148

here's a description of the service deployed in ASP.NET . I need a java Client to access this service. After writing a java client i have not been able to get the desired result. im getting an exception as follows
Exception in thread "main" Server returned HTTP response code: 500 for URL:
at Client.main(

The listing of the add method(ASP.NET) is as follows

The following is a sample SOAP request and response. The placeholders shown need to be replaced with actual values.

POST /test/HelloWorld.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: ""

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

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="" xmlns:xsd="" xmlns:soap="">
<addResponse xmlns="">

My Java File-->


public class Client {
public static void main(String[] args) throws Exception {

String SOAPUrl = "";
String xmlFile2Send = "C:\\Madhup Temp\\add.xml";

String SOAPAction = "";

// Create the connection where we're going to send the file.
URL url = new URL(SOAPUrl);
URLConnection connection = url.openConnection();
HttpURLConnection httpConn = (HttpURLConnection) connection;

// Open the input file. After we copy it to a byte array, we can see
// how big it is so that we can set the HTTP Cotent-Length
// property.

FileInputStream fin = new FileInputStream(xmlFile2Send);
ByteArrayOutputStream bout = new ByteArrayOutputStream();

// Copy the SOAP file to the open connection.

byte[] b = bout.toByteArray();

// Set the appropriate HTTP parameters.
httpConn.setRequestProperty( "Content-Length", String.valueOf( b.length ) );
httpConn.setRequestProperty("Content-Type","text/xml; charset=utf-8");
httpConn.setRequestMethod( "POST" );

// Everything's set up; send the XML that was read in to b.
OutputStream out = httpConn.getOutputStream();
out.write( b );

// Read the response and write it to standard out.

InputStreamReader isr = new InputStreamReader httpConn.getInputStream());
BufferedReader in = new BufferedReader(isr);

String inputLine;

while ((inputLine = in.readLine()) != null)


public static void copy(InputStream in, OutputStream out)
throws IOException {

// do not allow other threads to read from the
// input or write to the output while copying is
// taking place

synchronized (in) {
synchronized (out) {

byte[] buffer = new byte[256];
while (true) {
int bytesRead =;
if (bytesRead == -1) break;
out.write(buffer, 0, bytesRead);

Can anyone please help me out as to why i am not able to access the service and the reason ?
By the way the XML file - add.xml
I agree. Here's the link:
subject: web service + java Client
It's not a secret anymore!