客户端调用webservice的xfie和aixs2用法

第一种:

xfire:

  public String test1(){
//        SoapController(客户端自己定义的接口) 为服务端暴露出来的方法,方法名和参数必须和服务端的匹配
        Service srvcModel = new ObjectServiceFactory()
                .create(SoapController.class);
        XFireProxyFactory factory = new XFireProxyFactory(XFireFactory
                .newInstance().getXFire());

        SoapController srvc = null;
        try {
            srvc = (SoapController) factory.create(srvcModel, "http://XXX?wsdl");
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        String hello = srvc.hello();
        System.out.println(hello);
    }

第二种:

xfire:

    public String test2(){
        StringWriter sw = new StringWriter();
        Object[] objects = null;
//            Client client = new Client(new URL(interfaceWsdl));
        URL url = new URL("http://XXX?wsdl");
        HttpURLConnection httpConnection = (HttpURLConnection)url.openConnection();
        httpConnection.setReadTimeout(120000);//设置http连接的读超时,单位是毫秒,根据实际情况指定
        httpConnection.connect();
        Client client = new Client(httpConnection.getInputStream(), null);
        client.setProperty(CommonsHttpMessageSender.HTTP_TIMEOUT, String.valueOf( 120000));//设置发送的超时限制,单位是毫秒,根据实际情况指定
        client.setProperty(CommonsHttpMessageSender.DISABLE_KEEP_ALIVE, "true");
        client.setProperty(CommonsHttpMessageSender.DISABLE_EXPECT_CONTINUE, "true");
        Object[] opAddEntryArgs = new Object[] { "", "",
                "" };//参数列表
        try {
            objects = client.invoke("方法名称", opAddEntryArgs); //调用接口
        } catch (Exception e) {
            e.printStackTrace(new PrintWriter(sw, true));
        }
        return objects[0].toString();
    }

第三种:

axis2:

public static String test3() throws Exception {
    // 使用RPC方式调用WebService
    RPCServiceClient serviceClient = new RPCServiceClient();
    Options options = serviceClient.getOptions();
    options.setProperty(HTTPConstants.CHUNKED, "false");//设置不受限制.
    // 指定调用WebService的URL
    EndpointReference targetEPR = new EndpointReference("http://XXX");//wsdl的地址,不带wsdl
    options.setTo(targetEPR);
    // 指定sayHelloToPerson方法的参数值
    Object[] opAddEntryArgs = new Object[] { "", "",""};//参数列表
    // 指定方法返回值的数据类型的Class对象
    Class[] classes = new Class[] { String.class };
    // 指定要调用的sayHelloToPerson方法及WSDL文件的命名空间
    QName opAddEntry = new QName("http://XXX", "方法名");//xxx表示命名空间
    String str = (String) serviceClient.invokeBlocking(opAddEntry,
            opAddEntryArgs, classes)[0];
    return str;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值