• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Websphere WSDL2java - how to connect to webservice

 
akhil karthik
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ITS IS VERY URGENT.ANY HELP PLEASE...
 
Ranjeeth Chandra
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 [ http://ws.apache.org/axis2/download.cgi ] 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.

 
akhil karthik
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic