java webservice 接口调用

阅读更多

import javax.xml.namespace.QName;

import org.apache.axis.client.Call; 
import org.apache.axis.client.Service; 
import org.apache.tomcat.util.net.URL;

import javax.xml.namespace.QName; 
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.encoding.XMLType;

import java.lang.Integer; 


public class TestService {

 public static void main(String[] args) {
  
     String endpoint = "http://localhost:8080/SchoolService/SchoolManaPort?wsdl";
   Service service = new Service(); 
   System.out.println("=============1==================service "+service);
         try{ 
             Call call = (Call)service.createCall(); 
             System.out.println("=============2==================call "+call);
             //设置url 
             call.setTargetEndpointAddress(endpoint); 
             //注册服务端命名空间  
             call.setOperationName(new QName("http://school/","depart"));//WSDL里面描述的接口名称
             //设置返回值类型,这里返回的list 
             call.setReturnClass(String.class); 
             //设置输入参数,data1、data2需要根据wsdl中的名称来填,如果输入参数为map或list 中间参数为XMLType.XSD_HEXBINARY 
             call.addParameter("arg0", XMLType.XSD_STRING, ParameterMode.IN); 
             String reqXml = "02900000013201808170610001";
             Object[] param = new Object[]{reqXml}; 
             String returnxml = (String)call.invoke(param); 
             System.out.println( returnxml); 
         }catch(Exception e){ 
             e.printStackTrace(); 
         }
 }
 
 
 
}

你可能感兴趣的:(java webservice 接口调用)