微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

WebService_HelloWorld_笔记

  --创建服务端步骤
      1 定义服务接口和实现类
      2 给接口和实现类加上注解
      3 发布服务
        http://localhost:8888/ns?wsdl

        http://localhost:8888/ns?xsd=1

package biz.codeworm.ws;

import javax.jws.WebResult;
import javax.jws.WebService;

@WebService()
public interface AddressWS {
	
	@WebResult
	public String getAddress();
	
	@WebResult(name="addrCode")
	public int getAddressCode();
	
	public String getAddrDesc();
	
}

package biz.codeworm.ws;

import javax.jws.WebResult;
import javax.jws.WebService;

@WebService(endpointInterface="biz.codeworm.ws.AddressWS")
public class AddressWSImpl implements AddressWS {

	@Override
	public String getAddress() {
		return "北京市";
	}

	@Override
	@WebResult(name = "addrCode")
	public int getAddressCode() {
		return 13000;
	}

	@Override
	@WebResult
	public String getAddrDesc() {
		return "北京是个美丽的城市";
	}

}

package biz.codeworm.ws;

import javax.xml.ws.Endpoint;

public class WSMain {

	public static void main(String[] args) {
		String url = "http://localhost:8888/ns";
		AddressWS addrWS = new AddressWSImpl();
		Endpoint.publish(url,addrWS);
	}

}

--创建客户端步骤
  命令:
  wsimpost -d d:/webservice/01/ -p mypackag -keep -verbose http://localhsot:..?wsdl
  命令解释:
  1 -d 生成代码的存放位置
  2 -p 生成代码的包
  3 -keep 表示生成源码
  4 -verbose 后面接发布的地址

package biz.codeworm.ws.client; import java.io.IOException; public class WSClient2 {     /**      * @param args      * @throws IOException      */     public static void main(String[] args) throws IOException { //        URL url = new URL("http://localhost:8888/ns?wsdl"); //        AddressWSImplService addrWSImpl = new AddressWSImplService(url);         AddressWSImplService addrWSImpl = new AddressWSImplService();         AddressWS addrWS = addrWSImpl.getAddressWSImplPort();         System.out.println(addrWS.getAddrDesc());     } }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐