zoukankan      html  css  js  c++  java
  • 通用的调用WebService的两种方法。(调用别人提供的wsdl)(转)

    转载自:http://blog.sina.com.cn/s/blog_65933e020101incz.html
    1、调用WebService的Client端采用jax-ws调用WebService;
    流程:
    1) 建立JavaProject;
    2) 建立WebServiceClient:
    (1) OtherèMyEclipseèWebServicesèWebServiceClient;
    (2) “Strategy”只能选jax-ws(不能选XFire);
    (3) 选用WSDL URL;((3)(4)两步表示只能用jax-ws采用WSDL解析的方式来调用WebService);
    (4) 下一步会提示加入jax-ws的包;
    (5) “Finish”后会自动产生很多的类;
    3) 手动设计本地调用WebService的类,流程:
    (1) 实例化一个Service:NumberPlusService srvc = new NumberPlusService()//为WebService中主类(包含各种接口)
    (2) 生成该WebService的本地代理:
    NumberPlusServicePortType delegate = srvc.getNumberPlusServiceHttpPort()
    (3) 通过该代理调用服务中的Operation:
    delegate.plus(4, 6)//接口中的方法


    2、通过url调用WebService
    public int String delegate(int a, int b) {
      String URL   = "http://localhost/WebServiceTest/services/NumberPlusService ?wsdl";
      Object[] results = null;
      try {
       Client client = new Client(new URL(URL));
       results = client.invoke("delegate", new Object[] { a,b});
      } catch (MalformedURLException e) {
       e.printStackTrace();
      } catch (Exception e) {
       e.printStackTrace();
      }
      return (int) results[0];
    }

  • 相关阅读:
    软考
    十步走-阅读笔记
    软著申请
    十步走-阅读笔记
    基于Ubuntu安装部署ZooKeeper
    基于Ubuntu安装JDK(OPenJDK8)
    Intern Day89
    阿里巴巴Java研发工程师技术一面
    面试
    6_moc.md
  • 原文地址:https://www.cnblogs.com/xihong2014/p/10920513.html
Copyright © 2011-2022 走看看