[Axis2與Eclipse整合開發Web Service系列之三] 服務端傳回值

來源:互聯網
上載者:User

標籤:des   style   blog   http   io   color   os   ar   使用   

前言

在前面的三篇中

[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>


[Axis2與Eclipse整合開發Web Service系列之三] 服務端傳回值

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.