1.用jdk命令生成客户端文件
命令调用webservice接口:【AuctionService?wsdl】
wsimport -keep -d d:\web -s d:\web http://ip:port/projectname/AuctionService?wsdl -p com.sw.webservice
2.把生成的文件拷贝项目里编写调用文件如下:
- public class WebserviceClent {
- static String WSDLOCATION = ”http://ip:port/projectname/AuctionService?wsdl”;
- static String SERVICENAME = ”AuctionServiceService”;
- static String NAMESPACE = ”http://webservice.sw.com/”;
- static String PORTNAME = ”AuctionServicePort”;
- public static void main(String[] args) {
- try {
- URL myurl = new URL(WSDLOCATION);
- QName sn = new QName(NAMESPACE,SERVICENAME);
- QName pn = new QName(NAMESPACE,PORTNAME);
- Service service = Service.create(myurl,sn);
- com.sw.webserviceinfo.AuctionService auctionService = (com.sw.webserviceinfo.AuctionService)service.getPort(pn,com.sw.webserviceinfo.AuctionService.class);
- auctionService.findRcbwBasic(“22050020121105000004″);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }