The moose likes Web Services and the fly likes Websphere WSDL2java - how to connect to webservice Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Websphere WSDL2java - how to connect to webservice" Watch "Websphere WSDL2java - how to connect to webservice" New topic

Websphere WSDL2java - how to connect to webservice

akhil karthik

Joined: Jul 06, 2009
Posts: 13
Hello all,

Someone has put up a webservice and provided me with a WSDL file. I now need to connect to this service from my java-projects.

I know some of the theory behind webservices but now I need to put some code into practice for the first time... Can anyone point out how to go about it from here?

I am using Rad 6 websphere environment.
akhil karthik

Joined: Jul 06, 2009
Posts: 13
Ranjeeth Chandra

Joined: Sep 19, 2008
Posts: 7
Here are some steps which might help you -

serach google for a batch file - wsdl2java - which would generate all the required java from the WSDL.
You would have to set the required parameters in one of the java files, which you have to find out. It is the class which makes the webservice call.
You will get the response object back if you have 1.properly connected to the webservice 2. you have properly set the required parameters. Look the WSDL to know what are all required parameters

Shailesh Welankar
Ranch Hand

Joined: Dec 30, 2002
Posts: 35

You will need to generate a client to access the service with the WSDL provided.

Use Axis2 or CXF to generate the client. I find Axis2 simple enough to jump start the client stub generation and web service access.
Download the Axis2 v1.5 binary distro from their Apache site [ ] and unzip on your local drive.
Set the JAVA_HOME and AXIS2_HOME path on your PC. Run the wsdl2java bat file in the bin folder of the Axis2 home directory.
You will need to provide the output directory and WSDL URL to it as parameters. The client stub would get generated in the specified directory.
Copy this files in your project (if not already there) and place in some logical project directory hierarchy (like a client sub-folder of your class files st6ructure).
Then you will need to create the ClientController class. This class will have the logic to give actual calls to the client stub and will be used from within your other classes that implement the business logic. The code in the ClientController class to give service calls follows the steps as below -
1. Get the request object from the generated client stub. This is usually named as <ServiceName>ServiceRequest. (make sure you have the generated client stub imported in this class).
2. Provide any request parameters to it by using setters.
3. Get the stub object in similar fashion as Request object and set the requestHeader object (can be null) and the request object to it.
4. Using this stub object, give a call to the remote service (you may want to set the URL of the service in the constructor firstly), and collect the return object in some variable with an appropriate datatype.
5. You now have the response - use it any way you like it !!! Its that simple !!

Hope this helps you and I have understood and answered you question properly.

--Shailesh Welankar
SCDJWS 1.4 | SCBCD 5.0 | SCWCD 1.4 | SCJP 1.4 | Preparing for SCEA 5
akhil karthik

Joined: Jul 06, 2009
Posts: 13
THANKS SO MUCH FOR THE INPUTS.. CAN YOU GUIDE ME WHAT I SHOULD DO to connect to BASIC Authentication. I have valid username,password. But WSDL provided has basic authentication set to authenticate the users. ANY HELP in this? I don't want to be container specific settings like setting global security on the server i am using. I would like to get this from say like property files.
akhil karthik

Joined: Jul 06, 2009
Posts: 13
I.e. i will frame it this way, My client app is calling a webservice which has basic authentication. How should i approach using java. I used wsdl2java to generate the stubs etc. But when i am actually calling the methos in the service, i am getting 401 unauthOrised..
I agree. Here's the link:
subject: Websphere WSDL2java - how to connect to webservice
It's not a secret anymore!