一.开发服务器端
1.编写代码
@WebService (SEI和SEI的实现类)
@WebMethod(SEI中的所有方法)
1 @WebService2 public interface Hellows {3 4 @WebMethod5 public String sayHello(String name);6 }
1 @WebService 2 public class HellowsImpl implements Hellows{ 3 4 @Override 5 public String sayHello(String name) { 6 7 System.out.println("Server " + name); 8 name = name +"~~~"; 9 return name;10 }11 12 }
2.发布WebService
工具类Endpoint(发布发布WebService)
1 public class TestWebService { 2 3 public static void main(String[] args) { 4 5 String address = "http://localhost:8989/com.moonmars"; 6 Hellows implementor = new HellowsImpl(); 7 Endpoint.publish(address, implementor); 8 System.out.println("发布成功"); 9 }10 }
二.开发客户端
1.通过浏览器的方式
查看wsdl文档: ......?wsdl 可以利用Eclipse的webservice浏览器查看请求和响应消息
2.利用编码的方式访问
1.JDK中的wsimport.exe工具生成客户端代码
wsimport -keep url //url 可以为本地文件位置 也可以为网络地址
wsimport -keep http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl 最好先把文件位置转到当前工程的src下
2.借助自动生成的代码编写请求代码