AXIS2远程调用WebService示例(MyEclipse+AXIS)

摘自:https://www.cnblogs.com/Sunnor/p/6246850.html
import java.rmi.RemoteException;

import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.ServiceException;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;

   public void goRespDial(String xml){
        String url="http://10.10.0.154:9002/khyx/webservice/cMSInter?wsdl";
                 //预定义失败的默认返回值
                 String result = "call failed!";
                //步骤1 构建 org.apache.axis.client.Service 对象
                 Service service = new Service();
                 Call call;
                 try {
                     // 步骤2:通过org.apache.axis.client.Service对象创建一个Call,需要强转为 org.apache.axis.client.Call类型
                     call = (Call) service.createCall();
                    // 步骤3:设置目标地址,即需要访问的webservice地址
                     call.setTargetEndpointAddress(url);
                     // 步骤4:设置调用的方法名
                     call.setOperationName("respDial");
        
                    // 步骤5: 设置参数名
                    call.addParameter("xml", // 参数名
                             XMLType.XSD_STRING, // 参数类型:String
                             ParameterMode.IN); // 参数模式:'IN' or 'OUT'
        
                     // 步骤6:设置返回值类型
                    call.setReturnType(XMLType.XSD_STRING); // 返回值类型:String
                    String name = xml;
                      //步骤7 :调用call.invoke(Object[] obj)方法
                      result = (String) call.invoke(new Object[] { name });// 远程调用
                  } catch (ServiceException e) {
                      e.printStackTrace();
                  } catch (RemoteException e) {
                     e.printStackTrace();
                  }
                 System.out.println(result);
        
    }

猜你喜欢

转载自blog.csdn.net/dhq_blog/article/details/82891237