webservice 参数怎么传

2025-04-12 02:57:16

1、第一步:搭建开发环境。打开myeclipse新建工程webService--创建代码public class ServiceDemo{ public ServiceDemo(){ } public String getName(){ return "hhh"; }}

webservice 参数怎么传
webservice 参数怎么传
webservice 参数怎么传

2、第二步:生成webservice服务类。如题步骤如下图所示:

webservice 参数怎么传
webservice 参数怎么传
webservice 参数怎么传
webservice 参数怎么传
webservice 参数怎么传

3、第三步:测试服务类。启动报错找不到类,这是由于jar缺失,引入jar步骤如下图所示。再次启动:访问结果如下

webservice 参数怎么传
webservice 参数怎么传
webservice 参数怎么传
webservice 参数怎么传
webservice 参数怎么传
webservice 参数怎么传

4、第四步:生成客户端。具体创建步骤如下图所示:

webservice 参数怎么传
webservice 参数怎么传
webservice 参数怎么传
webservice 参数怎么传
webservice 参数怎么传
webservice 参数怎么传
webservice 参数怎么传
webservice 参数怎么传
webservice 参数怎么传

5、第五步:测试客户端。具体代码如下:public static void main(Stri艘绒庳焰ng[] args) { Serv足毂忍珩iceDemoService sd = new ServiceDemoService(); ServiceDemoDelegate sdg = sd.getServiceDemoPort(); System.out.println(sdg.getName()); }测试结果如下:成功

webservice 参数怎么传

6、第六步:传参数。1、修改服务类:在服务类的获取name的方法中传参数String,在客户端加参数string,分别打印结果成功。服务类端口:package com.service;public class ServiceDemo{ public ServiceDemo(){ } public String getName(String name){ if("zhangsan".equals(name)){ return "张三"; } return "李四"; }}重新执行:(第二步:生成webservice服务类。)2、修改测试类。重新生成测试客户端:重新执行“第四步:生成客户端”。分别在测试类中传参数zhangsan和其它值。具体代码如下:import com.service.ServiceDemoDelegate;import com.service.ServiceDemoService;public class Test { public static void main(String[] args) { ServiceDemoService sd = new ServiceDemoService(); ServiceDemoDelegate sdg = sd.getServiceDemoPort(); System.out.println(sdg.getName("zhangsan")); System.out.println(sdg.getName("lisi")); }}

webservice 参数怎么传
webservice 参数怎么传

7、第七步:测试。启动服务-webservice的服务端,执行客户端的调用--》输入两个不同的参数--》执行 调用如下图所示:

webservice 参数怎么传
webservice 参数怎么传
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢