微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

This tutorial shows how to create a simple Web service from a WSDL file.

author: ZJ 07-3-20

 

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.

 

 

相关介绍

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐