java 调用webservice接口过程

  1. 已知存在webservice服务端地址,如http://127.0.0.1:8080/hello?wsdl

  1. 使用jdk自带的wsimport工具生成客户端代理类,命令如下:

wsimport -d D:\test -keep-verbose  http://127.0.0.1:8080/hello?wsdl
  1. 将生成好的代码复制到自己的工程中,调用如下:

public static void main(String[] args) throws MalformedURLException {
        Map map = new HashMap();
        map.put("pk_oa", "2022121901");
        map.put("djrq", "2022-12-16 15:20:42");
        map.put("zy", "报销内容111");
        map.put("jsfs", "0001Z0100000000000XZ");
        map.put("zyx2", "1");
        map.put("zyx1", "1");
        map.put("zyx4", "1");
        map.put("fydwbm", "1");
        map.put("fydeptid", "1");
        map.put("hbbm", "1");
        map.put("customer", "1");
        map.put("szxmid", "1");
        map.put("jkbxr", "1");
        
        JSONObject map1 = new JSONObject();
        map1.put("defitem12", "1001A11000000001JVB5");
        map1.put("defitem13", "1001A21000000006D8BP");
        map1.put("defitem14", "20");
        map1.put("defitem15", "10.00");
        map1.put("amount", "100");
        map1.put("defitem16", "10");
        map1.put("defitem17", "12");
        List list = new ArrayList();
        list.add(map1);
        map.put("items", list);

        //创建WSDL地址,不是服务地址  
        URL url = new URL("http://193.168.1.30:8080/uapws/service/nc.oa.nin.itf.IRecOAInfo?wsdl");  
        //创建服务名称  
        //参数1:namespaceURL--命名空间地址(wsdl文档中的targetNamespace)
        //参数2:服务试图名字(wsdl文档服务名称,例如:)
        QName qname = new QName("http://itf.nin.oa.nc/IRecOAInfo", "IRecOAInfo");  
          
        //Service创建视图  
        Service service = Service.create(url, qname); 
        //获取服务实现类 
        //参数解释:IRecOAInfoPortType 服务端口(wsdl文档中服务端口的name属性,例如:)
        IRecOAInfoPortType mobileCodeWSSoap = service.getPort(IRecOAInfoPortType.class);  
        //调用查询方法  
        String result = mobileCodeWSSoap.saveBxdBill(JSON.toJSONString(map));
        System.out.println(result);
    }
  1. 引用jar包如下


        
            org.apache.axis
            axis
            1.4
        
        
            commons-discovery
            commons-discovery
            0.2
            
                
                    commons-logging
                    commons-logging
                
            
        
        
            org.apache.axis
            axis-jaxrpc
            1.4
        
        
            org.apache.axis
            axis-saaj
            1.4
        
        
            wsdl4j
            wsdl4j
            1.6.3
        
        

你可能感兴趣的:(java)