java直接调用WebServices接口

根据url 调用:http://10.220.105.60:8080/pdyjws/baseMethod.asmx

/**
     * 调用webservice接口,返回string类型的json值
     * @return
     */
    public String getWebServices(){
    	//获取webservice接口地址
        String url = "http://10.220.105.60:8080/pdyjws/baseMethod.asmx";
        //获取域名地址,server定义的
        String soapaction = "http://tempuri.org/";
        Service service = new Service();
        //调用的方法
        String method="getDailyFast";
        //调用的参数
        String startdate="2019-02-11";
        String enddate="2019-02-12";
        String result="";
        try {
              Call call = (Call) service.createCall();
              call.setTargetEndpointAddress(url);
              //设置要调用的方法
              call.setOperationName(new QName(soapaction,method));
              call.addParameter(new QName(soapaction, "startdate"), // 设置要传递的参数--要和接口方提供的参数名一致
                      org.apache.axis.encoding.XMLType.XSD_STRING,
                      javax.xml.rpc.ParameterMode.IN);
              call.addParameter(new QName(soapaction, "enddate"), // 设置要传递的参数
                      org.apache.axis.encoding.XMLType.XSD_STRING,
                      javax.xml.rpc.ParameterMode.IN);
              //设置要返回的数据类型
              call.setReturnType(new QName(soapaction,method), String.class);
              call.setUseSOAPAction(true);
              call.setSOAPActionURI(soapaction+method);
              //调用方法并传递参数
              result = (String) call.invoke(new Object[]{startdate,enddate});
             } catch (ServiceException e) {
            	 bislogger.error("[PdfDataTask][getWebServices]Exception1",e);
            } catch (Exception e) {
            	 bislogger.error("[PdfDataTask][getWebServices]Exception2",e);
            }
        return result;
        }

需要的jar包,这些jar包不能少:


		
		    org.apache.axis
		    axis
		    1.4
		
		
		    commons-discovery
		    commons-discovery
		    0.2
		
		
		    wsdl4j
		    wsdl4j
		    1.6.2
		
		
		    javax.xml
		    jaxrpc
		    1.1
		
		
			commons-httpclient
			commons-httpclient
			3.1
		
		
		
		    org.apache.httpcomponents
		    httpclient
		    4.5.7
		
				
		
		    org.apache.httpcomponents
		    httpmime
		    4.5.7
		

 

你可能感兴趣的:(webservices接口)