zoukankan      html  css  js  c++  java
  • Axis与Axis2 java客户端 实例

    Axis1 Code:

    /**
    * @Description Axis1客户端
    *
    @author 无处不在 QQ:381969898
    * @DateTime 上午10:13:18
    */
    public class Axis1Client {

    public String execute() throws Exception {

    // 外接口返回值
    String result = "";
    // 初始化传递的参数
    String parmInfo1 = "value1" ;
    String parmInfo2
    = "value2" ;
    // webService参数信息
    String webServiceAddress = "";
    String webServiceMethod
    = "";

    Service service
    = new Service();
    Call call
    = (Call) service.createCall();

    // 加载WSDL,方法名,nameSpace
    webServiceAddress = "http://ip:<port>/xxx/services/xxx?wsdl" ;
    webServiceMethod
    = "method" ;
    String nameSpace
    = "" ;

    String soapActionURI
    = nameSpace + "/" + webServiceMethod;
    // 设置wsdl
    call.setTargetEndpointAddress(new java.net.URL(webServiceAddress));
    // 设置访问的方法名
    call.setOperationName(new QName(nameSpace, webServiceMethod));
    // 定义参数对象
    call.setUseSOAPAction(true);
    call.setSOAPActionURI(soapActionURI);
    // 设置访问的方法名
    call.setOperationName(webServiceMethod);
    OperationDesc oper
    = new OperationDesc();

    // String 类型 传递参数
    oper.addParameter(new javax.xml.namespace.QName(nameSpace, "parmInfo1"),
    new javax.xml.namespace.QName(nameSpace, "string"),
    java.lang.String.
    class,
    org.apache.axis.description.ParameterDesc.IN,
    false, false);
    oper.addParameter(
    new javax.xml.namespace.QName(nameSpace, "parmInfo2"),
    new javax.xml.namespace.QName(nameSpace, "string"),
    java.lang.String.
    class,
    org.apache.axis.description.ParameterDesc.IN,
    false, false);
    // 返回值类型
    oper.setReturnType(XMLType.XSD_STRING);
    call.setTimeout(
    5000);
    // 执行
    result = (String) call.invoke(new Object[] { parmInfo1 , parmInfo2 });
    System.out.println(result);
    return result;
    }
    }

      

    Axis2 客户端:

    /**
    * @Description Axis2客户端
    *
    @author 无处不在 QQ:381969898
    * @DateTime 上午10:14:42
    */
    public class Axis2Client {

    public String execute() throws Exception {

    // 使用RPC方式调用WebService
    RPCServiceClient serviceClient = new RPCServiceClient();
    Options options
    = serviceClient.getOptions();
    // 指定调用WebService的URL
    EndpointReference targetEPR = new EndpointReference(
    "http://ip:<port>/axis2/services/XXX");
    options.setTo(targetEPR);
    // 指定method方法的参数值
    String parmInfo1 = "value1" ;
    int parmInfo2 = 12 ;
    Object[] opAddEntryArgs
    = new Object[] {parmInfo1,parmInfo2};
    // 指定method方法返回值的数据类型的Class对象
    Class[] classes = new Class[] {String.class};
    // 指定要调用的method方法及WSDL文件的命名空间
    QName opAddEntry = new QName("http://ws.apache.org/axis2", "method");
    // 调用method方法并输出该方法的返回值
    System.out.println(serviceClient.invokeBlocking(opAddEntry, opAddEntryArgs, classes)[0]);
    // 下面是调用method2方法的代码,这些代码与调用method方法的代码类似
    classes = new Class[] {int.class};
    opAddEntry
    = new QName("http://ws.apache.org/axis2", "method2");
    System.out.println(serviceClient.invokeBlocking(opAddEntry,
    new Object[]{}, classes)[0]);
    return null;
    }
    }

      

  • 相关阅读:
    SharePoint 2013 商务智能报表发布
    sharepoint designer web 服务器似乎没有安装microsoft sharepoint foundation
    SharePoint 2013 Designer系列之数据视图
    SharePoint 2013 Designer系列之数据视图筛选
    SharePoint 2013 Designer系列之自定义列表表单
    SharePoint 2013 入门教程之创建及修改母版页
    SharePoint 2013 入门教程之创建页面布局及页面
    SharePoint 2010 级联下拉列表 (Cascading DropDownList)
    使用SharePoint Designer定制开发专家库系统实例!
    PL/SQL Developer 建立远程连接数据库的配置 和安装包+汉化包+注册机
  • 原文地址:https://www.cnblogs.com/macula/p/2155966.html
Copyright © 2011-2022 走看看