SOA练习通过myeclipse将wsdl文件生成javabean.docx
- 文档编号:26574573
- 上传时间:2023-06-20
- 格式:DOCX
- 页数:18
- 大小:552.96KB
SOA练习通过myeclipse将wsdl文件生成javabean.docx
《SOA练习通过myeclipse将wsdl文件生成javabean.docx》由会员分享,可在线阅读,更多相关《SOA练习通过myeclipse将wsdl文件生成javabean.docx(18页珍藏版)》请在冰豆网上搜索。
SOA练习通过myeclipse将wsdl文件生成javabean
实验五WSDLWeb服务描述语言
1、实验目的和要求
(1)理解WSDL的概念及特点;
(2)理解WSDL的专用术语;
(3)掌握WSDL的组成元素;
(4)理解抽象接口和具体实现的定义;
(5)掌握WSDL的设计方法;
(6)掌握从WSDL到Java类的“自上而下”的WebService设计方法。
2、实验环境
(1)PC机;
(2)互联网;
(3)谷歌、XX搜索引擎;
(4)MyEclipse;
(5)HttpAnalyzer。
3、实验内容
(1)使用MyEclipse设计WSDL;
(2)根据WSDL创建WebService;
(3)创建客户端使用WebService;
(4)侦测通信请求和响应。
4、实验实现过程
模拟情景:
系统分析师:
需要设计一个WebService,功能为:
a)传入两个整数,返回它们的和;
b)传入一个字符串,返回它的长度。
根据此要求,设计好WebService的WSDL文档,交给开发工程师。
开发工程师:
根据接收到的WSDL文档,创建相应的Java类,并完成功能的实现代码。
请认真听老师讲解以上实验过程,留意屏幕演示步骤。
主要步骤包括:
(1)使用MyEclipse可视化工具设计WSDL文档,使WebService的描述符合需求;
(2)根据第
(1)步生成的WSDL,使用MyEclipse创建WebService的基本框架;
(3)完成具体的实现代码;
(4)部署WebService到服务器;
(5)创建WebService客户端以检测服务运行效果;
(6)必要时使用HttpAnalyzer侦测通信请求和响应。
建一个webservise项目,选择JAX-WS:
选择新建的工程,右键new->Other->myEclipse->WebService->WSDL,点击Next,进入下个页面配置如下:
targetNamespace把www.example.org改为localhost:
8080
Finish以后:
在圈里面的标签要添加一个方法(以为我此前已经再新建了一个方法:
Plus和Len方法)
改为:
这里要改:
选择新建的工程,右键new->Other->myEclipse->WebService->webService,点击Next,进入下个页面配置如下:
创建一个测试类测试:
结果:
代码区:
WSDL:
xmlversion="1.0"encoding="UTF-8"standalone="no"?
>
definitionsxmlns: soap="http: //schemas.xmlsoap.org/wsdl/soap/"xmlns: tns="http: //localhost: 8080/webserviseTest/"xmlns: wsdl="http: //schemas.xmlsoap.org/wsdl/"xmlns: xsd="http: //www.w3.org/2001/XMLSchema"name="webserviseTest"targetNamespace="http: //localhost: 8080/webserviseTest/"> types> schematargetNamespace="http: //localhost: 8080/webserviseTest/"> elementname="Plus"> complexType> sequence> elementname="x"type="xsd: float"/> elementname="y"type="xsd: float"> element> sequence> complexType> element> elementname="PlusResponse"> complexType> sequence> elementname="sum"type="xsd: float"/> sequence> complexType> element> elementname="Len"> complexType> sequence> elementname="str"type="xsd: string"> element> sequence> complexType> element> elementname="LenResponse"> complexType> sequence> elementname="len"type="xsd: int"> element> sequence> complexType> element> schema> types> messagename="PlusRequest"> partelement="tns: Plus"name="parameters"/> message> messagename="PlusResponse"> partelement="tns: PlusResponse"name="parameters"/> message> messagename="LenRequest"> partname="parameters"element="tns: Len"> part> message> messagename="LenResponse"> partname="parameters"element="tns: LenResponse"> part> message> portTypename="webserviseTest"> operationname="Plus"> inputmessage="tns: PlusRequest"/> outputmessage="tns: PlusResponse"/> operation> operationname="Len"> inputmessage="tns: LenRequest"> input> outputmessage="tns: LenResponse"> output> operation> portType> bindingname="webserviseTestSOAP"type="tns: webserviseTest"> bindingstyle="document"transport="http: //schemas.xmlsoap.org/soap/http"/> operationname="Plus"> operationsoapAction="http: //localhost: 8080/webserviseTest/Plus"/> input> bodyuse="literal"/> input> output> bodyuse="literal"/> output> operation> operationname="Len"> operationsoapAction="http: //localhost: 8080/webserviseTest/Len"/> input> bodyuse="literal"/> input> output> bodyuse="literal"/> output> operation> binding> servicename="webserviseTest"> portbinding="tns: webserviseTestSOAP"name="webserviseTestSOAP"> addresslocation="http: //localhost: 8080/wsdlToJavabeanTest/webserviseTestSOAP"/> port> service> definitions> WebServiceTest类: packagecom.ren.wsdlToJavabeanTest; importjavax.jws.WebMethod; importjavax.jws.WebParam; importjavax.jws.WebResult; importjavax.jws.WebService; importjavax.xml.ws.RequestWrapper; importjavax.xml.ws.ResponseWrapper; @WebService(name="webserviseTest",targetNamespace="http: //localhost: 8080/webserviseTest/") publicinterfaceWebserviseTest{ /** * *@paramy *@paramx *@returnreturnsfloat */ @WebMethod(operationName="Plus",action="http: //localhost: 8080/webserviseTest/Plus") @WebResult(name="sum",targetNamespace="") @RequestWrapper(localName="Plus",targetNamespace="http: //localhost: 8080/webserviseTest/",className="com.ren.wsdlToJavabeanTest.Plus") @ResponseWrapper(localName="PlusResponse",targetNamespace="http: //localhost: 8080/webserviseTest/",className="com.ren.wsdlToJavabeanTest.PlusResponse") publicfloatplus(@WebParam(name="x",targetNamespace="")floatx, @WebParam(name="y",targetNamespace="")floaty); /** * *@paramstr *@returnreturnsint */ @WebMethod(operationName="Len",action="http: //localhost: 8080/webserviseTest/Len") @WebResult(name="len",targetNamespace="") @RequestWrapper(localName="Len",targetNamespace="http: //localhost: 8080/webserviseTest/",className="com.ren.wsdlToJavabeanTest.Len") @ResponseWrapper(localName="LenResponse",targetNamespace="http: //localhost: 8080/webserviseTest/",className="com.ren.wsdlToJavabeanTest.LenResponse") publicintlen(@WebParam(name="str",targetNamespace="")Stringstr); } webserviseTestSOAPImpl类: packagecom.ren.wsdlToJavabeanTest; importjavax.jws.WebMethod; importjavax.jws.WebParam; importjavax.jws.WebResult; importjavax.jws.WebService; importjavax.xml.ws.RequestWrapper; importjavax.xml.ws.ResponseWrapper; @javax.jws.WebService(endpointInterface="com.ren.wsdlToJavabeanTest.WebserviseTest",targetNamespace="http: //localhost: 8080/webserviseTest/",serviceName="webserviseTest",portName="webserviseTestSOAP") publicclasswebserviseTestSOAPImpl{ publicfloatplus(floatx,floaty){ //TODOAuto-generatedmethodstub //thrownewUnsupportedOperationException("Notimplementedyet."); returnx+y; } publicintlen(Stringstr){ //TODOAuto-generatedmethodstub //thrownewUnsupportedOperationException("Notimplementedyet."); returnstr.length(); } } Test类: packagecom.ren.wsdlToJavabeanTest; publicclassTest{ publicstaticvoidmain(String[]args){ WebserviseTest_Serviceservice=newWebserviseTest_Service(); WebserviseTestws=service.getWebserviseTestSOAP(); System.out.println(ws.plus(1,1)); System.out.println(ws.len("student")); } }
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- SOA 练习 通过 myeclipse wsdl 文件 生成 javabean
![提示](https://static.bdocx.com/images/bang_tan.gif)