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

来源:互联网 发布:小刀娱乐网源码php 编辑:程序博客网 时间:2024/06/06 04:20

前言

在前面的三篇中

[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 0
原创粉丝点击