- New a Java Project, say WebServiceClientDemo, in Eclipse.
- Select WebServiceClientDemo project, right click > New > Other... > Web Services > Web Service Client. Click next.
- Type http://localhost:5566/WebServiceDemo/services/HelloWorld?wsdl in service definition. Click finish. Eclipse will generate several Java classes for us. For example, the code of HelloWorld.java is
/** * HelloWorld.java * * This file was auto-generated from WSDL * by the Apache Axis 1.4 Apr 22, 2006 (06:55:48 PDT) WSDL2Java emitter. */ package demo; public interface HelloWorld extends java.rmi.Remote { public java.lang.String greeting(java.lang.String in0) throws java.rmi.RemoteException; }
- New a Java class to call greeting() method - Main.java:
package demo; public class Main { public static void main(String[] args) { try { HelloWorldService service = new HelloWorldServiceLocator(); HelloWorld helloWorld = service.getHelloWorld(); System.out.println(helloWorld.greeting("Plover")); } catch (Exception e) { e.printStackTrace(); } } }
- Run as Java Application. We should see the following message in Console:
Hello World! Plover!
2011年10月12日 星期三
[Java] Creating a Web Service Client in Eclipse
Step-by-step:
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言