wood burning stoves 2.0*
The moose likes Web Services and the fly likes Invoking a webservice from a servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Invoking a webservice from a servlet" Watch "Invoking a webservice from a servlet" New topic

Invoking a webservice from a servlet

Prashanth Chandra
Ranch Hand

Joined: Dec 07, 2005
Posts: 79
I am able to invoke a webservice using a Standalone java program. I am using the below command to invoke the web service.

java com.javasrc.webservices.age.AgeServiceClient -lhttp://localhost:8080/axis/services/AgeService "Siva" 33

Now if I write the whole code in a method I am not able to retreive the values into the servlet. Can any please suggest me how to invoke a web service from a servlet/JSP. Please tell if there any sites for this.

Here is my Client code:

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import org.apache.axis.utils.Options;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
public class AgeServiceClient
public static void main(String [] args)
Options options = new Options(args);
String endpointURL = options.getURL();
String name;
Integer age;
args = options.getRemainingArgs();
if ((args == null) || (args.length < 2))
name = "NoName";
age = new Integer( 0 );
name = args[ 0 ];
age = new Integer( args[ 1 ] );
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress( new java.net.URL(endpointURL) );
call.setOperationName( new QName("http://age.webservices.javasrc.com", "age") );
call.addParameter( "arg1", XMLType.XSD_STRING,ParameterMode.IN);
call.addParameter( "arg2", XMLType.XSD_INT, ParameterMode.IN);
call.setReturnType( org.apache.axis.encoding.XMLType.XSD_STRING);
String ret = (String) call.invoke( new Object[]{name,age});
System.out.println("Age result : " + ret);
catch (Exception e)

Thanks in advance
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12755
Now if I write the whole code in a method I am not able to retreive the values into the servlet.

What happens when you try?

There is nothing magical about invoking a webservice from the servlet environment - you do have to provide for various failure possibilities and Thread safety.

Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
The same code should be running from a servlet too..What exactly are you getting when you try this.

Rahul Bhattacharjee
LinkedIn - Blog
Don't get me started about those stupid light bulbs.
subject: Invoking a webservice from a servlet
Similar Threads
Unable to receive result from Web Service Method
Simple Web Service using Axis
how to invoke web service implemented in MS.NET
Use Web Service
My first webservice call