java动态调用webservice服务端



java动态调用webservice服务端

1.用jdk命令生成客户端文件

命令调用webservice接口:【AuctionService?wsdl】

       wsimport -keep -d d:\web -s d:\web http://ip:port/projectname/AuctionService?wsdl -p com.sw.webservice
2.把生成的文件拷贝项目里编写调用文件如下:

  1. public class WebserviceClent {
  2.     static String WSDLOCATION = ”http://ip:port/projectname/AuctionService?wsdl”;
  3.     static String SERVICENAME = ”AuctionServiceService”;
  4.     static String NAMESPACE = ”http://webservice.sw.com/”;
  5.     static String PORTNAME = ”AuctionServicePort”;
  6.     public static void main(String[] args) {
  7.         try {
  8.             URL myurl = new URL(WSDLOCATION);
  9.             QName sn = new QName(NAMESPACE,SERVICENAME);
  10.             QName pn = new QName(NAMESPACE,PORTNAME);
  11.             Service service = Service.create(myurl,sn);
  12.             com.sw.webserviceinfo.AuctionService auctionService = (com.sw.webserviceinfo.AuctionService)service.getPort(pn,com.sw.webserviceinfo.AuctionService.class);
  13.             auctionService.findRcbwBasic(“22050020121105000004″);
  14.         } catch (Exception e) {
  15.             e.printStackTrace();
  16.         }
  17.  }
  18. }