WebService到底是什么?
Web Service也叫XML Web Service WebService是一种可以接收从Internet或者Intranet上的其它系统中传递过来的请求,轻量级的独立的通讯技术。是:通过SOAP在Web上提供的软件服务,使用WSDL文件进行说明,并通过UDDI进行注册。
一言以蔽之:WebService是一种跨编程语言和跨操作系统平台的远程调用技术。
一、准备工作(以下为本实例使用工具)
1、MyEclipse10.7.1
2、JDK 1.6.0_22
二、创建服务端
1、创建【Web Service Project】,命名为【TheService】。
2、创建【Class】类,命名为【ServiceHello】,位于【com.hyan.service】包下。
3、编写供客户端调用的方法,即编译方法代码。
4、进行编译
说明:编译失败的话,请将该项目引用的jdk设置为1.6.0_17版本或更高版本
5、测试结果
测试地址:http://localhost:9001/Service/ServiceHello?wsdl
三、生成客户端
1、创建【Web Service Project】,命名为【TheClient】。
2、命令提示窗口执行生成命令。
格式:wsimport -s "src目录" -p “生成类所在包名” -keep “wsdl发布地址”
示例:
wsimport -s G:\\workspace\\webService\\TheClient\\src -p com.hyan.client -keep http://localhost:9001/Service/ServiceHello?wsdl
说明:
1)"src目录"地址不可含空格
2)“wsdl发布地址”不要漏了“?wsdl”
3、刷新项目,检查生成类
四、最终测试
1、创建【Class】类,命名为【ServiceTest】,位于【com.hyan.test】包下。
2、编写测试方法,调用服务端方法,并打印返回的结果。
五、注意事项
1、JDK版本过低问题
报类似如下的异常:runtime modeler error: Wrapper class com.hyan.service.jaxws.GetValue is not found. Have you run APT to generate them?
原因:JDK版本低于1.6.0_17
解决方法:调整该服务端项目所引用的JDK版本为安装的高版本JDK
2、生成命令路径含空格问题
报类似如下的异常:directory not found: G:\SVN_FILE\GB\05
原因:客户端src路径不可含有空格
解决方法:在不含空格路径的文件夹下重新创建客户端即可。
3、生成命令不完整问题
报类似如下的异常:[ERROR] failed.noservice=Could not find wsdl:service in the provided WSDL(s):
<li class="tool-item tool-active is-like "><a href="javascript:;"><svg class="icon" aria-hidden="true"> <use xlink:href="#csdnc-thumbsup"></use> </svg><span class="name">点赞</span> <span class="count">1</span> </a></li> <li class="tool-item tool-active is-collection "><a href="javascript:;" data-report-click="{"mod":"popu_824"}"><svg class="icon" aria-hidden="true"> <use xlink:href="#icon-csdnc-Collection-G"></use> </svg><span class="name">收藏</span></a></li> <li class="tool-item tool-active is-share"><a href="javascript:;"><svg class="icon" aria-hidden="true"> <use xlink:href="#icon-csdnc-fenxiang"></use> </svg>分享</a></li> <!--打赏开始--> <!--打赏结束--> <li class="tool-item tool-more"> <a> <svg t="1575545411852" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5717" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M179.176 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5718"></path><path d="M509.684 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5719"></path><path d="M846.175 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5720"></path></svg> </a> <ul class="more-box"> <li class="item"><a class="article-report">文章举报</a></li> </ul> </li> </ul> </div> </div> <div class="person-messagebox"> <div class="left-message"><a href="https://blog.csdn.net/gtlishujie"> <img src="https://profile.csdnimg.cn/E/0/A/3_gtlishujie" class="avatar_pic" username="gtlishujie"> <img src="https://g.csdnimg.cn/static/user-reg-year/2x/9.png" class="user-years"> </a></div> <div class="middle-message"> <div class="title"><span class="tit"><a href="https://blog.csdn.net/gtlishujie" data-report-click="{"mod":"popu_379"}" target="_blank">gtlishujie</a></span> </div> <div class="text"><span>发布了25 篇原创文章</span> · <span>获赞 38</span> · <span>访问量 25万+</span></div> </div> <div class="right-message"> <a href="https://im.csdn.net/im/main.html?userName=gtlishujie" target="_blank" class="btn btn-sm btn-red-hollow bt-button personal-letter">私信 </a> <a class="btn btn-sm bt-button personal-watch" data-report-click="{"mod":"popu_379"}">关注</a> </div> </div> </div>