Client Code Examples
In Axis there is a tool called WSDL2Java that can be used to generate Java client stub code from a web service WSDL file. To use this tool you just run it with java from the command prompt:
java org.apache.axis.wsdl.WSDL2Java -a <WSDL URL>
Please notice that you must have java.exe in your path before running this and that all jar files used by Axis (found in the lib directory under your Axis installation directory) must be in your classpath before you can use the command above.
If successful the command above should result in a lot of new java classes being created for you. If we run this command with the NRG Consumer Search WSDL file as an input parameter then the following classes and interfaces should be generated:
WSDL2Java have a lot of optional parameters that can be used to specify which java package you want the generated code to be placed in, which directory they should be placed under etc. Please refer to the Axis user guide at http://ws.apache.org/axis/java/user-guide.html for a complete documentation on WSDL2Java.
Using the Generated Code
After you have generated client code with Axis you probably want to use the code. Here you will find a basic example code that shows how to use the Axis generated client code to perform a consumer search (please see the NRG Consumer Search section below for further information about this web service).
Client Code to Annual Report PDF
The following example code can be used when calling the Annual Report PDF service in the Bisgateway. This code uses a javax.activation.DataHandler, which holds the PDF file. It also uses SOAP with Attachments API for Java (SAAJ) and commons-httpclient 2.0 from Apache which can be downloaded at http://jakarta.apache.org/commons/httpclient/. Note: This code will be distributed as a ready-to-use component in the download section.
To use the tool you just type:
wsdl /l:CS /protocol:SOAP <WSDL URL>
into a Visual Studio Command Prompt. If you do this on the Consumer Search service WSDL for example it should generate a source file called NRGConsumerSearch.cs.
You can also use the Add Web Reference functionality in Visual Studio which will let you add a web service reference to your project by simply pointing out a WSDL file. This action will also generate client proxy code, much like above. Please refer to the Microsoft Visual Studio documentation for more information about how to do this.