加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

WTP1.0开发WebService之使用WSDL生成Service

发布时间:2020-12-17 02:52:26 所属栏目:安全 来源:网络整理
导读:This tutorial shows how to create a simple Web service from a WSDL file. author: ZJ 07-3-20 Blog: [url]http://zhangjunhd.blog.51cto.com/[/url] ? 1 .确定安装了 Apache Tomcat (这里使用 Tomcat5.0 ),新建一个 dynamic Web project 取名为 Area
This tutorial shows how to create a simple Web service from a WSDL file.

author: ZJ 07-3-20
Blog: [url]http://zhangjunhd.blog.51cto.com/[/url]

?

1.确定安装了Apache Tomcat(这里使用Tomcat5.0),新建一个dynamic Web project取名为 AreaProj

?

2.示例中使用的WSDL文档。(该文档定义了一个计算长方形面积的服务)
AreaService.wsdl

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://tempuri.org/AreaService/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="AreaService"
targetNamespace="http://tempuri.org/AreaService/">
? <wsdl:types>

<xsd:schema targetNamespace=http://tempuri.org/AreaService/

?xmlns:xsd="http://www.w3.org/2001/XMLSchema">

????? <xsd:element name="area" type="xsd:float"/>
????? <xsd:element name="parameters" type="tns:dimensions"/>
????? <xsd:complexType name="dimensions">
????? ??? <xsd:sequence>
????? ?????????? <xsd:element name="width" type="xsd:float"></xsd:element>
????? ?????????? <xsd:element name="height" type="xsd:float"></xsd:element>
????? ??? </xsd:sequence>
????? </xsd:complexType>
??? </xsd:schema>
? </wsdl:types>
? <wsdl:message name="CalculateRectAreaResponse">
??? <wsdl:part element="tns:area" name="area"/>
? </wsdl:message>
? <wsdl:message name="CalculateRectAreaRequest">
??? <wsdl:part element="tns:parameters" name="parameters"/>
? </wsdl:message>
? <wsdl:portType name="AreaService">
??? <wsdl:operation name="CalculateRectArea">
????? <wsdl:input message="tns:CalculateRectAreaRequest"/>
????? <wsdl:output message="tns:CalculateRectAreaResponse"/>
??? </wsdl:operation>
? </wsdl:portType>
? <wsdl:binding name="AreaServiceSOAP" type="tns:AreaService">
??? <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
??? <wsdl:operation name="CalculateRectArea">
????? <soap:operation soapAction="http://tempuri.org/AreaService/NewOperation"/>
????? <wsdl:input>
??????? <soap:body use="literal"/>
????? </wsdl:input>
????? <wsdl:output>
????? ??<soap:body use="literal"/>
????? </wsdl:output>
??? </wsdl:operation>
? </wsdl:binding>
? <wsdl:service name="AreaService">
??? <wsdl:port binding="tns:AreaServiceSOAP" name="AreaServiceSOAP">
????? <soap:address location="http://tempuri.org"/>
??? </wsdl:port>
? </wsdl:service>
</wsdl:definitions>

?

?

3.将AreaService.wsdl放在/WebContent下,鼠标右键选中该文件,选择New-Other-WebService,配置如下。

?

?

4.一路Next,如果没有启动Tomcat,会提示Start Server。最后选择Finish

?

5.在/src下生成部分java文件,其中一个AreaServiceSOAPImpl.java。将其内容修改为如下所示。

?

6.在/WebContent/wsdl/下会生成AreaServiceSOAP.wsdl。鼠标右键选中该文件,选择New-Other-WebService Client,配置如下。

?

7.点击两个Next后,到达Client环境配置。配置如下。

?

8.选择Finish。出现如下画面。

?

9.选择calculateRectArea进行测试,计算长方形面积。测试结果如下。

?

10.查看传递的SOAP
request部分:

?

response部分:

?

11.参考资料
Eclipse WTP tutorials.

?

?

相关介绍

WTP1.0开发WebService之Java Class实例

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读