调用webservice(不用生成代码)

package com.demo.util;
import java.rmi.RemoteException;  
import javax.xml.namespace.QName;  
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;   
/**
 * jar包 axis.jar 和 jaxrpc.jar 和commons-discovery-0.2.jar和wsdl4j.jar
 */
public class CaClient {  
    public String invokeRemoteFuc() {  
        String endpoint = "wsdl地址";  
        String result = "call failed!";  
        Service service = new Service();  
        Call call;  
        try {  
            call = (Call) service.createCall();  
            call.setTargetEndpointAddress(endpoint);   
            call.setOperationName(new QName("命名空间","方法名"));  
            // 设置参数名  
            call.addParameter("arg0",   // 参数名  
                    XMLType.XSD_STRING, // 参数类型:String  
                    ParameterMode.IN);  // 参数模式:'IN' or 'OUT'  
            call.addParameter("arg1",
                    XMLType.XSD_INT,
                    ParameterMode.IN);
            call.addParameter("arg2",
                    XMLType.XSD_INT,
                    ParameterMode.IN);  
            // 设置返回值类型  
            call.setReturnType(XMLType.XSD_STRING); // 返回值类型:String  
            String arg0 = "abc2222";  
            String arg1 = "0";  
            String arg2 = "2017-12-28";
            result = (String) call.invoke(new Object[] { arg0,arg1,arg2 });// (参数名必须是arg?)
        } catch (ServiceException e) {  
            e.printStackTrace();  
        } catch (RemoteException e) {  
            e.printStackTrace();  
        }  
        return result;  
    }  
  
    // 测试  
    public static void main(String[] args) {  
        CaClient test = new CaClient();  
        String result = test.invokeRemoteFuc();  
        System.out.println(result);  
    }  
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值