您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 销售管理 > web service for android developing
于鑫蕾BTSmobile2012.04.01Webserviceforandroiddevelopingfirstofall,youneedtoknowthatwedevelopingourwebserviceprojectforandroidineclipseIDE.Secondly,androidoffersbuilt-inclasslibraryforwebserviceclientdeveloping,wecanusetheclasslibrarybyimportingorg.apache.http.*Otherwise,wecanusethird-partyclasslibrarysuchasKSOAP2android.NowLet’sgetstarted!ContentsGetStartdeployourwebserviceonserver......................................................................................1TestinvirtualClient...........................................................................................................................9TestinrealClient.............................................................................................................................11Firstweusethird-partylibraryKSOPA2tosupportourclientonandroid..............................12SecondwecreateSOAP/HTTPmessagemanullytotestourclient........................................16ThirdwetestinanormaljavaProjecttomakesomeoutreach..............................................17GetStartdeployourwebserviceonserverWeshoudtoknowhowcanwebuildanddeployourwebserviceonserver.Onserverside,awebserverandservletenginearerequired.WeuseTomcat6.Xinourdemo,soyouneedtoconfigurateTomcatineclipseIDE.Furthermore,anopensourceservicesframeworkisneeded,weuseApacheCXFframeworkinourdemo,CXFhelpsyoubuildanddevelopservicesusingfrontendprogrammingAPIS,likeJAX-WSandJAX-RS.TheseservicescanspeakavarietyofprotocolssuchasSOAP,XML/HTTP,RESTfulHTTP,orCORBAandworkoveravarietyoftransportssuchanHTTP,JMSorJBI.youcandownloadCXFlinkthisPreferencesWebservicesCXF2.XPreferenceinEclipseIDENowwecanbuildourwebservicedemoonserverpoint.1.FirstlyweshouldbuildaDynamicWebProject,causewebserviceneedtopublishonTomcat.FileNewDynamicWebProjectFigure1:afterclickedDynamicWebProject,youcanconfiguratelikethis于鑫蕾BTSmobile2012.04.01Nowweclickfinish.Asweallknow,Webservicescanbecreatedusingtwomethods:top-downdevelopmentandbottom-updevelopment.Top-downWebservicesdevelopmentinvolvescreatingaWebservicefromaWSDLfile.Bottom-upWebservicesdevelopmentinvolvescreatingaWebservicefromaJavabeanorenterprisebean.Weusebottom-up.Nowwecreatapackagenamedcom.capgemini.webserviceandaImplementedClassnamedLoginImpl.Figure2于鑫蕾BTSmobile2012.04.01NowwecancreatourwebserviceusingClassLoginImpllikethisRightclickLoginImpl,thenclickWebservices,thenclickCreateWebserviceFigure3于鑫蕾BTSmobile2012.04.01AfterclickCreateWebservicesyoucanseeadialogueboxlikethisFigure4于鑫蕾BTSmobile2012.04.01ClicknextWecreateSEIlikeFigure5于鑫蕾BTSmobile2012.04.01ClicknextFigure6justfollowme.6.ClickNexttomovetotheJAX-WSannotationsconfigurationpage:ThispageallowsyouaddtoJAX-WSannotationstotheSEIorImplementation(ifnotusinganexplicitSEI).TheJAX-WSannotationselementvaluesdefaulttothoseoutlinedintheJAX-WSspecifications.IftheImplementationbean/SEIcontainsoverloadedmethodstheJAX-WSannotationsaddedonthispageadjusttoresolvethoseconflicts.Figure7于鑫蕾BTSmobile2012.04.01Clicknext,Figure8于鑫蕾BTSmobile2012.04.01thenclicknextFigure9于鑫蕾BTSmobile2012.04.01ClickStartserverthenclickfinishNowyouhavefinishedbuildinganddeployyourwebservicesYoucantesttheWSDLinyouBrowserlikethis’tarealclient于鑫蕾BTSmobile2012.04.01NowrunthetestClassonjavaapplicationYoucanreceivedthemessageonclientsidelikethis2012-4-214:03:24org.apache.cxf.service.factory.ReflectionServiceFactoryBeanbuildServiceFromClass信息:CreatingService{}LoginServicefromclasscom.capgemini.webservice.LoginResponse:trueYoucanreceivedthemessageonserversidelikethis2012-4-214:03:25org.apache.cxf.services.LoginImplService.LoginImplPort.Login信息:InboundMessage----------------------------ID:2Address::UTF-8Http-Method:POSTContent-Type:text/xml;charset=UTF-8Headers:{Accept=[*/*],cache-control=[no-cache],connection=[keep-alive],于鑫蕾BTSmobile2012.04.01Content-Length=[217],content-type=[text/xml;charset=UTF-8],host=[localhost:8080],pragma=[no-cache],SOAPAction=[urn:Login],user-agent=[ApacheCXF2.5.2]}Payload:soap:Envelopexmlns:soap=:Bodyns2:loginxmlns:ns2=:login/soap:Body/soap:Envelope--------------------------------------2012-4-214:03:25org.apache.cxf.services.LoginImplService.LoginImplPort.Login信息:OutboundMessage---------------------------ID:2Encoding:UTF-8Content-Type:text/xmlHeaders:{}Payload:soap:Envelopexmlns:soap=:Bodyns2:loginResponsexmlns:ns2=:returntrue/ns2:return/ns2:loginResponse/soap:Body/soap:Envelope------------------
本文标题:web service for android developing
链接地址:https://www.777doc.com/doc-3368592 .html