How to consume a remote SOAP web service (JAX-WS)?

For the sake of explaining this scenario we will mix some theoretical aspects with a narration.
Disclaimer: This can be pretty stupid

Lets say this is the time where Mathematics hasn't been born yet. No cool mathematicians are born yet. But still you have numbers. So you dont know how to add or multiply or do anything with  the numbers. All of a sudden you need to add 2 numbers. Gladly there is a far far far away a machine that can add two numbers. So you are in luck.

That machine = Web service

Not so fast. You know that there is a such machine. But how the heck you can find it or frigging locate it. Just because you are such a lucky person, there is a wise old man in your villlage who knows all about every magical machinery crap that exist on this planet. So you can ask the directions to the adding machine.

Wise Old Man = UDDI

Just because you know the machine isnt mean that you can add 2 numbers. There is a specific way to present those 2 numbers to the machine and theres is a specific format that you get the result from the machine. Every machine has a manual ! So if you read the manual you can figure all about the machine.

Machine Manual = WSDL

Here you can parse the WSDL to have related stubs/proxies in 3 ways.

  1. Look at the WS and write the WSDL manually. Thats gonna be preeeeeety HARD.
  2. You can use an IDE like eclipse to do that. (3rd part tools)
  3. Use wsimport utility provided by JDK 6+ versions. https://docs.oracle.com/javase/6/docs/technotes/tools/share/wsimport.html [Note: wsimport <wsdl link> provides class files by deafult because after compilation it removes the .java files. If you want to have .java files add relevenat arguments to wsimport]
So once you know how to read the manual and hopefully you can understand the manual, you can operate it. Meaning you can add your two numbers.

This is just the basic of it. See how it is really done here.

Share:

0 comments: