天天看點

Eclipse搭建Web Service服務

1、建立動态Web工程(Dynamic Web Project),工程名為Server。編寫類HelloWorld。

package com.mysever;
 
public class HelloWorld {
 
     public String sayHello(String name){
           return name + ",你好";
     }
}      
Eclipse搭建Web Service服務

2、建立一個Web Service,在彈出的視窗中找到Service implementation一項:指定要釋出的服務。

Eclipse搭建Web Service服務

3、點選“Finish”後,Eclipse會自動建立WSDL file、生成一系列的配置文檔和自動導入6個jar封包件。

打開Tomcat服務,輸入http://localhost:8080/Server/services,通路Web Service。

Eclipse搭建Web Service服務
Eclipse搭建Web Service服務
Eclipse搭建Web Service服務
Eclipse搭建Web Service服務

4、建立工程(Java、Web工程均可),工程名為:client。

5、建立用戶端。建立過程File-->New-->Other->Web Service Client 。

Eclipse搭建Web Service服務

6、引用服務,在彈出來的對話框中找到Service definition,填寫服務端的URL位址,點選“Finsh”,自動導入需要的包和生成代碼檔案。

Eclipse搭建Web Service服務

7、建立測試類Test。

package com.test;
 
import java.rmi.RemoteException;
import com.mysever.HelloWorld;
import com.mysever.HelloWorldProxy;
 
public class Test {
   public static void main(String[] args) {
      try {
            HelloWorld service = new HelloWorldProxy();
            System.out.println(service.sayHello("達文西"));
      } catch (RemoteException e) {
            e.printStackTrace();
      }
   }
 
}      

PS:

程式警告

2015-3-20 13:51:12 org.apache.axis.utils.JavaUtils isAttachmentSupported

警告: Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart). Attachment support is disabled.

達文西,你好

解決方法:導入activation.jar和mail.jar

轉載于:https://www.cnblogs.com/XueRong-7/p/4503967.html