已阅读5页,还剩6页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Web Service学习之axis看着网上的资料学习了一下,做点笔记以防以后忘记。一、准备工作: 到axis官方网站下载相应的jar包,我下的是1.4final版。 /axis/二、建立项目: 直接在MyEclipse中建立了一个web项目。将相应的jar包拷贝到lib文件夹下三、创建一个WebService服务 直接创建一个类HelloClient.javaJava代码 1. packagecom; 2. 3. publicclassHelloServer 4. publicStringsayHello(Stringname) 5. returnHello+name; 6. 7. package com;public class HelloServer public String sayHello(String name) return Hello + name; axis支持两种方式创建,一种是将编写好的java文件改为*.jws文件。个人觉得这样不好,所以就用另外一种,采用在server-config.xml文件中配置的方式。注意:该文件位置为WEB-INF目录下Xml代码 1. 2. 4. 5. 6. 8. 9. 10. 11. 12. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 29. 31. 33. 34. 35. 36. 37. 38. /axis/wsdd/39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 55. 56. 58. 60. 62. 63. 64. 65. 66. 67. 68. 69. /axis/wsdd/ web.xml文件中的配置如下Xml代码 1. 2. 6. 7. 8. org.apache.axis.transport.http.AxisHTTPSessionListener 9. 10. 11. 12. 13. AxisServlet14. Apache-AxisServlet15. 16. org.apache.axis.transport.http.AxisServlet 17. 18. 19. 20. 21. AdminServlet22. AxisAdminServlet23. 24. org.apache.axis.transport.http.AdminServlet 25. 26. 10027. 28. 29. 30. SOAPMonitorService31. SOAPMonitorService32. 33. org.apache.axis.monitor.SOAPMonitorService 34. 35. 36. SOAPMonitorPort37. 500138. 39. 10040. 41. 42. 43. AxisServlet44. /servlet/AxisServlet45. 46. 47. 48. AxisServlet49. *.jws50. 51. 52. 53. AxisServlet54. /services/*55. 56. 57. 58. SOAPMonitorService59. /SOAPMonitor60. 61. 62. index.jsp63. 64. org.apache.axis.transport.http.AxisHTTPSessionListenerAxisServletApache-Axis Servletorg.apache.axis.transport.http.AxisServletAdminServletAxis Admin Servletorg.apache.axis.transport.http.AdminServlet100SOAPMonitorServiceSOAPMonitorServiceorg.apache.axis.monitor.SOAPMonitorServiceSOAPMonitorPort5001100AxisServlet/servlet/AxisServletAxisServlet*.jwsAxisServlet/services/*SOAPMonitorService/SOAPMonitorindex.jsp四、部署启动tomcat:在浏览器地址栏输入http:/localhost:8080/axisWebServiceServer/services可以看到已有的WebServicehttp:/localhost:8080/axisWebServiceServer/services/HelloServer?wsdl可以看到自己写的WebService五、测试调用WebServiceJava代码 1. packagecom; 2. 3. .MalformedURLException; 4. importjava.rmi.RemoteException; 5. 6. importjavax.xml.rpc.ServiceException; 7. 8. importorg.apache.axis.client.Call; 9. importorg.apache.axis.client.Service; 10. 11. publicclassHelloClient 12. 13. publicstaticvoidmain(Stringargs) 14. Stringstatus=aaaaaaa; 15. StringendPoint=http:/localhost:8080/axisWebServiceServer/services/HelloServer; 16. Stringoperation=sayHello; 17. Serviceservice=newService(); 18. 19. try 20. Callcall=(Call)service.createCall(); 21. call.setTargetEndpointAddress(.URL(endPoint); 22. call.setOperationName(operation); 23. Stringxml=(String)call.invoke(newObjectstatus); 24. System.out.println(xml); 25. catch(ServiceExceptione) 26. e.printStackTrace(); 27. catch(MalformedURLExceptione) 28. e.printStackTrace(); 29. catch(RemoteExceptione) 30. e.printStackTrace(); 31. 32. 33. 34. 35. package com;import .MalformedURLException;import java.rmi.RemoteException;import javax.xml.rpc.ServiceException;import org.apache.axis.client.Call;import org.apache.axis.client.Service;public class HelloClient public static void main(String args) String status = aaaaaaa;String endPoint = http:/localhost:8080/axisWebServiceServer/services/HelloServer;String operation = sayHello;Service service = new Service();try Call call = (Call) service.createCall();call.setTargetEndpointAddress(new .URL(endPoint);call.setOperationName(operation);String xml = (String) call.invoke(new Object status ); System.out.println(xml); catch (ServiceException e) e.printStackTrace(); catch (MalformedURLException e) e.printStackTrace(); catch (RemoteException e) e.printStackTrace();成功!java实现webservice实例一:首先创建个WEB工程,然后:http:/ws.A/axis/网站下载Axis安装包.当然还依赖其他包的,我这里在附件里上传了所有应用到得包,方便大家。axis.jarcommons-discovery-0.2.jarcommons-logging-1.0.4.jarjaxrpc.jarmailapi_1_3_1.jarsaaj.jarwsdl4j-1.5.1.jar二:然后就写wsdd 文件(注:其实这里真的不用,可以跳过第二步)为了生成这个文件:server-config.wsdddeploy.wsdd:/axis/wsdd/providers/java 在DOS下转换目录到%TOMCAT_HOME%webappsaxisWEB-INF,命令:java -cp %AXISCLASSPATH% org.apache.axis.client.AdminClient deploy.wsdd三:可以自己写第二步中的文件,代码如下:Wsdd代码1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 放到 WEB-INF 目录下 和web.xml一起,其中,WEB.XML可以直接从你下载的axis项目中拿来到自己工程就好,或者自己添加:Xml代码1. 2. AxisServlet3. org.apache.axis.transport.http.AxisServlet4. 5. 6. AxisServlet7. /services/*8. 四: 服务端提供的方法:Java代码1. packageserver;3. publicclassSayHello4. publicStringgetName(Stringname)5. returnhello=+name;6. 7. 五: 客户端访问服务端接口获得数据的方法:Java代码1. packageclient;3. importorg.apache.axis.client.Call;4. importorg.apache.axis.client.Service;6. publicclassTestClient8. publicstaticvoidmain(Stringargs)throwsException10. /指出service所在URL12. Stringendpoint=:8082/webservice/services/Login.jws;14. /创建一个服务(service)调用(call)16. Serviceservice=newService();18. Callcall=(Call)service.createCall();/通过service创建call对象19. 20. /设置service所在URL21. 22. call.setTargetEndpointAddress(.URL(endpoint);23. 24. /方法名(processService)与MyService.java方法名保持一致25. 26. call.setOperationName(getName);27. 28. /Object数组封装了参数,参数为ThisisTest!,调用processService(Stringarg)29
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年安全培训考核设备
- 企业危机公关解决方案研究
- 2026年医疗器械销售面试题库
- 2026年中国烟草总公司招聘面试供应链管理预测题
- 2026年秋季幼儿疾病预防健康知识
- 2026年急诊科医生知识全面提高
- 住宅冬季施工保障方案
- 商品砂浆配合比优化报告
- 公共厨房排水隔油处理方案
- 配送公司股权方案范本
- 2026年教科版三年级科学下册知识点梳理+教材习题答案
- 2026年4月18日黑龙江省纪委遴选笔试真题及解析(下午综合卷)
- 配偶对股权代持的知情同意书
- 建筑垃圾减量化监理监督实施细则
- 现代会议型酒店的推广策略研究
- 2026年长三角一体化发展指数与区域高质量发展评价体系
- 中国脑卒中康复指南(2025版)
- 2025年留置看护执勤规范笔试及答案
- 急救医学关键技能:胸外按压护理课件
- 生成式AI赋能的情境化小学英语教学策略研究教学研究课题报告
- 2026年高考语文全国二卷真题卷及答案
评论
0/150
提交评论