注册 | 登录 忘记密码? 51cto首页 | 博客 | 论坛 | 招聘
热点文章 [业内传闻]今天,7月25日..
 帮助

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


2007-03-25 12:36:09
版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://zhangjunhd.blog.51cto.com/113473/21440
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. 
 
相关介绍

本文出自 “子 孑” 博客,请务必保留此出处http://zhangjunhd.blog.51cto.com/113473/21440





    文章评论
 
2007-03-25 14:41:18
。。。学习。。

 

发表评论

昵   称:
验证码:  点击图片可刷新验证码  博客过2级,无需填写验证码
内   容: