您的位置:首页 > 编程语言 > PHP开发

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

2007-03-25 12:36 826 查看
This tutorial shows how to create a simple Web service from a WSDL file.[/i]
author: ZJ 07-3-20
Blog: http://zhangjunhd.blog.51cto.com/

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实例
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息