How do I call a web service from Java? (I have a perl script that does it)

Go To StackoverFlow.com

1

I've got a Java web app that needs to call a web service that sits on a different server.

Here's the code for the perl script I have that calls the service:

#!/usr/bin/perl -w

use SOAP::Lite;

my $user = 'user';
my $password = 'password';

my $loginURI = "http://someserver:8080/SakaiLogin.jws?wsdl";
my $scriptURI = "http://someserver:8080/sakai-axis/scripts/RosterService.jws?wsdl";

my $loginsoap = SOAP::Lite
-> proxy($loginURI)
-> uri($loginURI);

my $scriptsoap = SOAP::Lite
-> proxy($scriptURI)
-> uri($scriptURI);

my $session = $loginsoap->login($user, $password)->result;

# doSiteRoster(session, site_id, user_id)
my $result = $scriptsoap->doSiteRoster($session, "cfc338aa-acfb-41a6-a998-7e467afc297b", "djswartz")->result;

my $logout = $loginsoap->logout($session)->result;

exit;

Now, I'm thinking I can use javax.xml.ws.Service...Although I'm not quite sure how to go about it. Any direction would be awesome.

2012-04-04 21:46
by djswartz
there are a lot of tutorials and questions about that. Which ones have you tried - Bozho 2012-04-04 21:53
I've looked at a few. This one looked particularly decent (developing the client is near the bottom) http://bit.ly/HMepcO. Although I am a bit puzzled by the whole Endpoint Implementation Class concept...Like Hello port = service.getHelloPort(); The object port is a container to hold that tossed back from the service - djswartz 2012-04-04 21:58
This is a very open ended question. - check these out wsif, axis,jax-ws and choose what you lik - ring bearer 2012-04-04 23:59


0

I would use either :

  1. A simple http connection to the service port and send the XML yourself

Or

  1. Jax-ws as a client - you need to run wsimport on the Wsdl then use the generated java classes to call your service.
2012-04-04 23:47
by davidfrancis


0

You can find the simple examples http://code.google.com/p/simple-samples/source/checkout and documentation about them in http://code.google.com/p/simple-samples/downloads/list

2012-04-04 23:53
by srinik


0

This is a very open ended question. -There are quite a few frameworks/libraries in java to invoke webservices.

Check these frameworks out wsif, axis,jax-ws and choose what you like. While the first one is specifically for invocation, the last two are more full fledged and helps you created server side (your own services) as well as client side code.

2012-04-05 00:03
by ring bearer
Ads