This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Web Services and the fly likes WSDL - 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 "WSDL - how to connect to webservice" Watch "WSDL - how to connect to webservice" New topic
Author

WSDL - how to connect to webservice

Oggi Olli
Ranch Hand

Joined: Oct 11, 2007
Posts: 83
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?
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
What environment are you working in?

Many of the superplatforms (IBM Websphere, BEA WebLogic, Oracle Application Server, etc.) have their own Java enterprise specifications compliant web services toolkit. But even within each product line the support varies with the version of the product (which correlates to the level of Java enterprise specifications they comply with). More recent versions of JBoss (4.0.5 and up) support JBossWS. Spring has Spring-WS. However some people prefer to use an independent web services tool like Axis2 or Apache CXF (The ServerSide: Axis, Axis2, and CXF: Surveying the WS Landscape).

Strictly speaking you don't need a web services toolkit to access a web service, you can "simply" write your own SAAJ client (Java Web Services in a Nutshell: Chapter 3 SAAJ (PDF)). However that requires that you interpret the WSDL yourself. That is why most people prefer to use a WSDL-To-Java generation tool that generates static Java stubs from the WSDL. Depending on the web services toolkit that tool may be called wsdl2java, wscompile, wsimport, etc.

"3. WSDL2Java: Generate the Server-side Wrapper Code and Stubs For Easy Client Access" from Creating Web Services with Apache Axis shows an example of the process. However do not misinterpret this as an endorsement to use Axis 1.x. Axis 1.x is based on JAX-RPC, a specification that most likely won't be a required part of the Java Enterprise specification beyond Java EE 5. You're probably better off choosing something that is based on JAX-WS. Know what you are getting in to.

Have a look over the web services FAQ
Oggi Olli
Ranch Hand

Joined: Oct 11, 2007
Posts: 83
Thank you Peer for the extensive answer. Much appreciated.

My environment is Websphere applicaction server and IBM Rational Application Developer... So, if I understood correctly there is probably some automated tool for this in RAD?
Oggi Olli
Ranch Hand

Joined: Oct 11, 2007
Posts: 83
Thank you Peer for the extensive answer. Much appreciated.

My environment is Websphere applicaction server and IBM Rational Application Developer... So, if I understood correctly there is probably some automated tool for this in RAD?
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
Originally posted by Steinar Steinnes:
My environment is Websphere applicaction server and IBM Rational Application Developer


Which version?

JAX-WS only became available with the Feature Pack for Web Services for WebSphere Application Server V6.1

JAX-RPC versus JAX-WS
WebSphere Version 6 Web Services Handbook Development and Deployment
Oggi Olli
Ranch Hand

Joined: Oct 11, 2007
Posts: 83
We haven't upgraded to WAS 6.1 yet, so we are still using WAS 5.1 along with Java 1.4.
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
That would limit you to JAX-RPC.
WebSphere Version 5.1 Application Developer 5.1.1 Web Services Handbook

Search for WSDL2Client.
Oggi Olli
Ranch Hand

Joined: Oct 11, 2007
Posts: 83
Thank you. The WSDL2Java function worked out excellent! I was able to test the client with the built in test-client and everything that was posted to the Webservice was reflected in the database. Task 1 completed.

Now I do face another problem (or rather a barrier because I lack some basic understanding in this field).

I would like to use the Webservice client from my Java source project (or call it in some way from there). The client is located in my web-project. Any ideas on how to move forward with this?
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
I'm not sure that I understand your question.

Did you write a stand-alone Java client and now you would like to access the web service from a web client? The red book also has examples for a "web client". Access from a web client usually is no different than from a stand-alone client. However the application server may let you deploy the client (service) component so that you can access it via JNDI (if you want to).

how can I create the client that consume a web service
Oggi Olli
Ranch Hand

Joined: Oct 11, 2007
Posts: 83
Thanks for the link. Now I'm one step closer I think.

I'm using jndi to invoke the client in the following manner:

This throws an exception on line 3 CONVERTROLE(...)



The CONVERTROLE method takes 2 strings... What is it that I'm missing?
[ December 04, 2007: Message edited by: Steinar Steinnes ]
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
5.1 Redbook Figure 15-7: Have you used the "Web Service Client Test" wizard with "useJNDI" checked? Take a peak at the code that it generates - it may give you an idea on what you need to do.
Oggi Olli
Ranch Hand

Joined: Oct 11, 2007
Posts: 83
The test using generated JSPs didn't work out. I tried (with and with out jndi method included) and it gave me the same error as mentioned above.

Only thing that worked was the Web Services explorer tool (relates to figures 15-10 to 15-13) and the Universal Test Client. Both were able to access the webservice without problems. However I can't seem to find any of the code that they have produced...
Oggi Olli
Ranch Hand

Joined: Oct 11, 2007
Posts: 83
It seems there is some kind of setting that needs to be changed. Any ideas what kind of setting files the WSDL2client modifies?

The UTC runs fine when the source-files is put and run from the default package. If I move the files to another package and run the UTC from there it generates the same error as above.

I've also seen a class-cast exception when a method is supposed to return a stub and cast it to a object which is implemented by the stub class. This makes me think there must be some kind of setting that has to be tweaked.
Oggi Olli
Ranch Hand

Joined: Oct 11, 2007
Posts: 83
FYI I finally got it to work. It had to do with the namespace mapping (which mapped to the default package). I changed this to the desired package and everything worked out fine.

Thanks for your help Peer, I'll probably be back in this forum next time when I'll try to create a JAX-WS webservice... By the way, webservices is great fun, I've enjoyed every step of this learning process.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: WSDL - how to connect to webservice