[Axis2与Eclipse整合开发Web Service系列之三] 服务端返回值

前言

在前面的三篇中

[Axis2与Eclipse整合开发Web Service系列之一] 生成Web Service Client(将WSDl 转化成 Java代码)

[Axis2与Eclipse整合开发Web Service系列之二] Top-Down方式,通过WSDL逆向生成服务端

[Axis2与Eclipse整合开发Web Service系列之二] Top-Down方式,通过WSDL逆向生成服务端(续)

介绍了如何使用 axis2 与 eclipse 的开发web Service 。在第三篇中返回的是一个整型值 而且是返回一个值。

产生的 XXSOAPImpl,java 的代码如下:

直接这样, 是没什么问题。

但是如果返回多值的话, 产生的代码类似:


通过StringHolder 这个类来实现返回值。

可是通过Client 端调用有发现,无法取得这个值。


首先把这个问题的解法给出来: 把Elements 中 Request 和 Response 的名字设成大写

1. 当把Elements 中 Request 和 Response 的名字设成小写, 返回值以StringHolder实现

2. 当把Elements 中 Request 和 Response 的名字设成小写, 返回值产生新的Class实现


下面就以一个实际的例子来看这个问题。

本篇的例子是一个 天气预报的web service .

输入: city

输出: returnCode, returnMsg


一个例子

1. 首先建立一个 wsdl , 名字为 WeatherForecastService.wsdl

在设计视图中看到的效果如下:

2. 然后产生web service

产生后的服务端代码结构:

3. 产生的 deploy.wsdd 的内容如下


使用这种方式实现的server 端, 调用的时候发现无法获取返回值。

接下来, 修改配置, 把名字换成大写。

如何换?

1. 点击以下部分

2. 再点击

3. 接下来, 修改名字, 主要是改成大写



这里除了可以修改 名字之外, 还可以在 Types 区域中,添加新的类型,

添加后的类型可以在通过如下方式使用:

修改完成后, 重新产生新的代码:

Impl,java 文件

产生的deploy.wsdd


问题基本解决了


产生的WSDL

贴一下最总产生的 WSDL 的内容:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.oscar999.com/WeatherForecastService/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="WeatherForecastService" targetNamespace="http://www.oscar999.com/WeatherForecastService/">
  <wsdl:types>
    <xsd:schema targetNamespace="http://www.oscar999.com/WeatherForecastService/">    
       <xsd:complexType name="WeatherResponse">
      	<xsd:sequence>
      		<xsd:element name="returnCode" type="xsd:string"></xsd:element>
      		<xsd:element name="returnMsg" type="xsd:string"></xsd:element>
      	</xsd:sequence>
      </xsd:complexType>
      
      <xsd:element name="GetWeatherRequest">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element maxOccurs="1" minOccurs="1" name="city" type="xsd:string"/>
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
      <xsd:element name="GetWeatherResponse"
      	type="tns:WeatherResponse">
      </xsd:element>
    </xsd:schema>
  </wsdl:types>
  
  <wsdl:message name="getWeatherRequest">
    <wsdl:part element="tns:GetWeatherRequest" name="parameters"/>
  </wsdl:message>
  <wsdl:message name="getWeatherResponse">
    <wsdl:part element="tns:GetWeatherResponse" name="parameters"/>
  </wsdl:message>
  <wsdl:portType name="WeatherForecastService">
    <wsdl:operation name="getWeather">
      <wsdl:input message="tns:getWeatherRequest"/>
      <wsdl:output message="tns:getWeatherResponse"/>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="WeatherForecastServiceSOAP" type="tns:WeatherForecastService">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="getWeather">
      <soap:operation soapAction="getWeather" style="document"/>
      <wsdl:input>
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="WeatherForecastService">
    <wsdl:port binding="tns:WeatherForecastServiceSOAP" name="WeatherForecastServiceSOAP">
      <soap:address location="http://www.oscar999.com/WeatherForecastService"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

oscar999

送以玫瑰,手留余香

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值