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()); ?? ?} } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |