webservice不加密Webservice跨平台远程调用技术_第1页
webservice不加密Webservice跨平台远程调用技术_第2页
webservice不加密Webservice跨平台远程调用技术_第3页
webservice不加密Webservice跨平台远程调用技术_第4页
webservice不加密Webservice跨平台远程调用技术_第5页
已阅读5页,还剩27页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Webservicehttpsoapxml数据格式传输。webservice的底层通信原理是基于的Socket服务端packagepackageimportimportjava.io.IOException;importimport*@authorpublicclassWeatherServer@throwspublicstaticvoidmain(String[]args)throwsException//socketServerSocketserverSocket=newServerSocket(1234); whilewhile(true)//Socketsocket=//获得 DataInputStreamdataInputStream=newDataInputStream(////StringcityName=//////StringresultString=//}}}Socketpackagepackageimportimportjava.io.IOException;importimport*@author*@throws@throwspublicstaticvoidmain(String[]args)throwsExceptionwhile(true)////获得 DataOutputStreamdataOutputStream=newDataOutputStream(//获得 DataInputStreamdataInputStream=newDataInputStream(////StringcityName= ////StringresultString=System.out.println(cityName天气查询结果为:}}} 开发( webservicepackagepackageimportimport基于jax-ws的webservice服务*@authorpublicclassWeatherServer*查询天气服务方publicStringqueryWeather(StringcityName)System.out.println("正在查询cityName的天气StringresultString=return}*@parampublicstaticvoidmain(String[]args)//发布webservicenew}}wsdl3porttypewebservicewsimport1wsimportwebservice在 packagepackageimportimport webservice客户@authorpublicclassClient*@parampublicstaticvoidmain(String[]args)//创建webservice服务WeatherServerServiceweatherServerService=//得到服务端WeatherServerweatherServer//调用webservice服务方StringStringresultString=郑州}}XmlServiceBinging协议体的格式Porttype服务端点Message消息体wsdlservice WSDL生成客户端调用类,使用wsimportWsimport–s.packagepackageimport@authorpublicclassClientpublicstaticvoidmain(String[]args)=String =List<String>resultStrings=for(String}}}Wsimport通过使用myeclipsesoap协议tcp/ipmonitersoapSoap1.1Encoding:UTF-8Http-Method:Encoding:UTF-8Http-Method:POST Content-Length=[221],content-type=[text/xml;charset=UTF-8],Pragma=[no-cache],Pragma=[no-cache],SOAPAction=[""],User-Agent=[ApacheCXF2.4.2]} Headers:{}风力:东北风6jax-ws发布为web工第一步:jaxws-ri-2.2.8的扩展包web工程jarweb第四步:编写服务端代码,编写方法与之前学习jax-wswsgencmd进入工程下Soap1.1wsgen- -cpWebRoot\WEB-INF\classes soap1.2 - - - webWEB-INFsun-jaxws.xml文<?xml<?xmlversion="1.0"encoding="UTF-/xml/ns/jax-<endpointwsdl='WEB-url-第七步:在web工程的web.xml中添加及<servlet- Soap1.2使用jax-wsRI发布soap1.2接口,soap1.2协议格式Address:Encoding:UTF-8Http-Method:POST Host=[00:12345],Pragma=[no-cache],User-Agent=[ApacheCXF2.4.2]} Headers: ℃ 7CXF基CxfSOAspringSOAPath=%JAVA_HOME%\bin;%CXF_HOME%\bin;java工程cxfjarpackagepackageimportpublicinterfaceWeatherServerInterfacepublicResultqueryWeather(StringpublicStringqueryWatherSimple(String}packageimportimportjavax.jws.W importjavax.jws.WebService;import @author publicclassWeatherServerimplementsWeatherServerInterfacepublicResult QueryWebxmlClientqueryWebxmlClient=newQueryWebxmlClient();List<String>resultList=queryWebxmlClient.queryWather(cityName);StringtemperString=StringstataString=resultList.get(6);Resultresult=newResult();returnresult;} QueryWebxmlClientqueryWebxmlClient=newQueryWebxmlClient();List<String>resultList=queryWebxmlClient.queryWather(cityName);returnreturn}*@parampublicstaticvoidmain(String[]args)}}packagepackageimportCXF发布jaxws@authorpublicclassServer*@parampublicstaticvoidmain(String[]args)JaxWsServerFactoryBeanjaxWsServerFactoryBean=////指定服务实现}}wsdl分别使用wsimport和wsdl2java**wsdl2java可以生成soap1.1和方式1,直接使用packagepackageimportimportpublicclassClientpublicstaticvoidmain(String[]args) }}方式2,使用javax.xml.ws.Service调用客户packagepackageimportimportimportimportimportpublicclassClient3publicstaticvoidmain(String[]args)MalformedURLExceptionURLurl=new QNameqName=new Serviceservice=Service.create(url,WeatherServerInterfaceweatherServerInterface=} 方式3JaxwsProxyFactoryBean调用服务端packagepackageimportimportpublicclassClient3publicstaticvoidmain(String[]args)//JaxWsServerFactoryBeanJaxWsProxyFactoryBeanclient=new//wsdl =}}Aop的编程思想(面向切面)输入器在方法进入前执行packagepackageimportimportimportCXF发布jaxws@authorpublicclassServer*@parampublicstaticvoidmain(String[]args)//创建JaxWsServerFactoryBeanJaxWsServerFactoryBeanjaxWsServerFactoryBeannew////指定webservice//输 //输 }}CxfspringwebCXFJARpackagepackageimportpublicinterfaceWeatherServerInterfacepublicResultqueryWeather(StringpublicStringqueryWatherSimple(String packagepackageimportimportjavax.jws.W importjavax.jws.WebService;import@author= publicResultList<String>resultList=queryWebxmlClient.queryWather(cityName);StringtemperString=StringstataString=resultList.get(6);Resultresult=newResult();returnresult;}List<String>resultList=return}*@parampublicstaticvoidmain(String[]args)}}<?xmlversion="1.0"encoding="UTF-<?xmlversion="1.0"encoding="UTF-<!--STARTSNIPPET:beans--<beansxmlns=""""<bean<bean<!--ENDSNIPPET:beans--CXFcxf-<?xmlversion="1.0"encoding="UTF-<?xmlversion="1.0"encoding="UTF-<beansxmlns=""""<importresource="classpath:META-INF/cxf/cxf.xml"<importresource="classpath:META-INF/cxf/cxf-servlet.xml"<jaxws:endpointoWorld"address="/weather"web.xmlSpringweb.xmlCXF<description>ApacheCXF 第八步:启动web:_1javaproject工2)加cxfjar - 4)7CXF深入开Cxf服务端 __cxfs客户端 __cxfs具体流程步骤参见:资料文件夹下的webservice用户名令牌机制CXF+Spring+struts2Struts2:mvc框架1struts2jarstruts2webservice访2spring管理struts2action3spring管理业务类在上一节cxf和spring整功的基础上进行操作。第一步:将struts2的jar加入工程jarstruts2jarspring和struts2jar包action第四步:action和jsp整合,struts2的配置文件第五步:web.xmlstruts2的过虑器1spring<bean factory-bean="weatherClientFactory"factory-<beanid="weatherClientFactory"<property <property 2webservice服务。spring天气查询DAO<bean packagepackageimportpublicinterfaceWeatherQueryService//publicResultqueryWeatherBycityName(String} servicespring天气查询业务bean<bean <propertyname="queryWebxmlClient"<propertyname="seatherWebServiceSoap"第四步:编写strutspackagepackageimportimportimport定义天气查询@authorpublicclassWeatherActionextendsActionSupport//privateString//privateResult//privateWeatherQueryServicep

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论