Accessing a Web service

Hi,

I need to know how we can access a web service that is running in a remote machine in java. For this purpose i created a simple web service and i have exposed a simple method that returns a string (no input parameters). The WSDL that was generated had a URL specified in a

<wsdlsoap:address location="http://localhost:8080/ITDWeb/services/BUBWebService"/>

tag. Now i want to know how i can call this from a standalone java class and store the returned string.

thanks,

Dilip

[547 byte] By [dilip_jsfa] at [2007-11-27 5:27:38]
# 1

I also need to know if there are separate ways to access webservices running on Axis and JAX-WS environment. I got this piece of code to access a Axis webservice,

import java.net.MalformedURLException;

import java.net.URL;

import java.rmi.RemoteException;

import javax.xml.namespace.QName;

import javax.xml.rpc.ServiceException;

import org.apache.axis.client.Call;

import org.apache.axis.client.Service;

public class WebServiceInvoker {

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

String endPoint = "http://localhost:8080/SampleWebService/services/SampleService";

Service service = new Service();

try {

Call call = (Call) service.createCall();

call.setTargetEndpointAddress(new URL(endPoint));

call.setOperationName(new QName("http://DefaultNamespace", "getName"));

String ret = (String) call.invoke(new Object[] {"Hi Dilip"});

System.out.println(ret);

} catch (ServiceException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (MalformedURLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (RemoteException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

Can the same code be used to access a JAX-WS webservice? Or is there any generic code that can do the job?

Thanks,

Dilip

dilip_jsfa at 2007-7-12 14:49:20 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
The JAX-WS documentation should be helpful. You can get access to it from http://jax-ws.dev.java.net.
dkohlerta at 2007-7-12 14:49:20 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...