栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

java 调用webservice接口

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

java 调用webservice接口

RPC调用webservice接口

maven支持包:

  		
            org.apache.axis
            axis
            1.4
        
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;

import javax.xml.namespace.QName;

public static void main(String[] args) {
        try {
        	//接口地址
            String endpoint = "http://192.168.0.111:10086/webServices/xxxwebServices";
            //webservice接口的namespace
            String targetNamespace = "http://namespace.com";
            // 直接引用远程的wsdl文件
            // 以下都是套路
            Service service = new Service();
            Call call = (Call) service.createCall();
            call.setTargetEndpointAddress(new java.net.URL(endpoint));
            // WSDL里面描述的接口名称
            call.setOperationName(new QName(targetNamespace, "interfaceName"));
			//这里是我的业务xml参数列表,可以根据自己的情况,修改这个方法。
            String businessSystemOnlineNum = getXml("306699", "2022-07-08 11:00:00", "xxxxxxx");
		//打印下
            System.out.println("businessSystemOnlineNum=" + businessSystemOnlineNum);
		//param为webservice中接口的参数名
            call.addParameter("param",
                    org.apache.axis.encoding.XMLType.XSD_DATE,
                    javax.xml.rpc.ParameterMode.IN);// 接口的参数
            call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);// 设置返回类型
			//businessSystemOnlineNum为构建的参数
            String result = (String) call.invoke(new Object[]{businessSystemOnlineNum});
            // 给方法传递参数,并且调用方法
            System.out.println("result is " + result);
        } catch (Exception e) {
            System.err.println(e.toString());
        }
    }


    
    private static String getXml(String areaCode, String time, String apiName) {


        StringBuffer str = new StringBuffer();
        //固定头
        str.append("");

        //参数的列表根据业务设定,来自己修改。
        //str.append("");
        //str.append("");
        //str.append(areaCode);
        //str.append("");
        //str.append("");
        //str.append("");
        //str.append("");
        return str.toString();

    }
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1014810.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号