In order to conveniently access a Web service, regardless of its implementation language, a Java application can use proxy classes which offer a type-safe and abstract view on the Web service. The following sections describe two ways of generating these proxies:
- Using the JDK tool wsimport. (We recommend this alternative)
- Using tooling provided by Eclipse JBoss Tools.
This procedure uses standardized JAX-WS technology (part of Java EE). It does, however, require more manual work than alternative B.
- From the command line, execute "wsimport -keep <URL of WSDL>". This will generate Java source and class files.
- Above command assumes that your PATH environment variable includes the "bin" folder from the JDK installation. If this is not the case, modify the environment variable or use the full path to wsimport.
- Import the generated source files into your Eclipse project: "File->Import" -> "General > File System"
- Depending on the Web service, several message and data classes will be generated. Furthermore, there will be a service class which inherits from javax.xml.ws.Service. Instantiate this class or, in a managed environment, use dependency injection with the annotation @WebServiceRef (see lecture). The service instance will offer a method that returns a proxy providing the Web service operation(s).
B. Eclipse JBoss Tools
Proxies generated by this procedure use Apache Axis 1.4.
- Create the project that will access the web service, for example a plain Java project or an appropriate Java EE project.
- Right-click the project node in the "Project Explorer" and select "New -> Other". Choose "Web Services > Web Service Client" and press "Next".
- Enter the URL of the WSDL into the field "Service definition". Move the slider down to "Develop client". Finish the wizard.
- The wizard will import some JARs and create several Java classes. In order to access the Web service from your code, look for a class ending with "Proxy".