---
title: "WebService二——使用Eclipse开发WebService及各种调用方式"
author: "luweifeng1983"
date: "2016-09-09T17:19:25Z"
tags: []
categories: ["编程语言"]
slug: "webservice-eclipse-webservice"
draft: false
lastmod: "2016-09-09T17:37:28Z"
id: 2323580
url: "https://quicker.iteye.com/blog/2323580"
---

eclipse生成服务端及使用axis调用参见：[http://blog.csdn.net/tarenahuangdw/article/details/16119033](http://blog.csdn.net/tarenahuangdw/article/details/16119033)

eclipse生成web服务client项目，调用web服务参见：[http://www.oschina.net/question/1473586\_152018?fromerr=xtxngGfo](http://www.oschina.net/question/1473586_152018?fromerr=xtxngGfo)

 

附件webserver项目为通过eclipse自动生成web服务，地址：[http://localhost:8080/webserver/services/Hello?WSDL](http://localhost:8080/webserver/services/Hello?WSDL)

附件webClient项目为在eclipse中新建web服务客户端项目自动生成调用所需文件，只需要写一个调用类即可:

```
package com.lwf.client;

import com.lwf.server.HelloServiceLocator;
import com.lwf.server.HelloSoapBindingStub;

public class TestClient {
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try{
		// TODO Auto-generated method stub
		  HelloServiceLocator service = new HelloServiceLocator();
		  java.net.URL url = new java.net.URL("http://localhost:8080/webserver/services/Hello?WSDL");
		  HelloSoapBindingStub stub = new HelloSoapBindingStub(url, service);
          String hello = stub.sayHello("boy");
          System.out.println(hello);
          String bye = stub.sayByeBye();
          System.out.println(bye);
          stub.print();
         
     } catch (Exception e) {
         e.printStackTrace();
	 }
	}
}
```

 不过这种方式如果服务端修改了，又要重新生成客户端代码，可以使用axis另写调用程序，具体参见：附件axis调用：CallWebService，注意CallWebService项目中需要另外加入mail.jar和activation.jar包