2013-01-05 74 views
0

我有一個使用AXIOM實現的Axis2 Web服務,該服務返回一個String列表。來自Axis2 Web服務的OMElement的C#客戶端

Java中運行的客戶端代碼片段如下所示。

// * send SOAP message 
    sender.fireAndForget(requestObject); 

    // * get response 
    OMElement reponseObject = sender.sendReceive(requestObject); 

    // * iterator for String 
    Iterator elementItr = reponseObject.getChildElements(); 

    while(elementItr.hasNext()) 
    { 
     OMElement element = (OMElement)elementItr.next(); 

     // * print each message 
     System.out.println(element.getText()); 
    } 

我需要實現一個c#客戶端,使用上述服務。

我已經能夠測試一個返回單個String對象的c#客戶端,如下所示。

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using HDMClient.hdssWS; 

namespace HDMClient 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
     HDMClient.hdssWS.StockQuoteServicePortTypeClient client = new hdssWS.StockQuoteServicePortTypeClient("StockQuoteServiceHttpSoap11Endpoint"); 

     client.update("apple", 1232.123); 
     Console.WriteLine(client.getPrice("apple")); 
     Console.ReadLine(); 
     } 
    } 
} 

在app.config中的消息類型是「MTOM」,並在axis2.xml配置在WAS設置爲

<parameter name="enableMTOM">true</parameter> 

我可以處理一個String響應。

但我不知道如何處理上面的String列表。

我搜索了類似的情況

但它看起來像沒有我面對的情況。

你有什麼想法嗎?搜索的

回答

0

時間發生了一些解決辦法,其中不使用AXIOM,但基於POJO

Web服務。

這裏是返回字符串列表的服務。

package samples.quickstart.service.pojo; 

import java.util.HashMap; 
import java.util.ArrayList; 
import java.util.List; 

public class StockQuoteService { 
    private HashMap map = new HashMap(); 

    public List<String> getPrice(String symbol, int number) { 
    Double price = (Double) map.get(symbol); 

    List<String> retValue = new ArrayList<String>(); 

    retValue.add("1"); 
    retValue.add("2"); 

    return retValue; 
} 

public void update(String symbol, double price) { 
    map.put(symbol, new Double(price)); 
} 
} 

而在Reference.cs在.NET項目,我加

[System.ComponentModel.EditorBrowsableAttribute  (System.ComponentModel.EditorBrowsableState.Advanced)] 
    HDMClient.hdssWS.getPriceResponse HDMClient.hdssWS.StockQuoteServicePortType.getPrice(HDMClient.hdssWS.getPriceRequest request) 
    { 
     return base.Channel.getPrice(request); 
    } 

    public string [] getPrice(string symbol, int number) 
    { 
     HDMClient.hdssWS.getPriceRequest inValue = new HDMClient.hdssWS.getPriceRequest(); 
     inValue.symbol = symbol; 
     inValue.number = number; 
     HDMClient.hdssWS.getPriceResponse retVal = ((HDMClient.hdssWS.StockQuoteServicePortType)(this)).getPrice(inValue); 
     return [email protected]; 
    } 

    [System.ComponentModel.EditorBrowsableAttribute (System.ComponentModel.EditorBrowsableState.Advanced)] 
    void HDMClient.hdssWS.StockQuoteServicePortType.update(HDMClient.hdssWS.update request) 
    { 
     base.Channel.update(request); 
    } 

    public void update(string symbol, double price) 
    { 
     HDMClient.hdssWS.update inValue = new HDMClient.hdssWS.update(); 
     inValue.symbol = symbol; 
     inValue.price = price; 
     ((HDMClient.hdssWS.StockQuoteServicePortType)(this)).update(inValue); 
    } 

如果你在看代碼,我沒有在通用從C#使用List或ArrayList中。

返回值是字符串數組。 - >(public string [] getPrice(string symbol,int number))

而c#客戶端代碼如下所示。

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using HDMClient.hdssWS; 

namespace HDMClient 
{ 
class Program 
{ 
    static void Main(string[] args) 
    { 
     HDMClient.hdssWS.StockQuoteServicePortTypeClient client = new hdssWS.StockQuoteServicePortTypeClient("StockQuoteServiceHttpSoap11Endpoint"); 

     client.update("apple", 1232); 

     string [] result = client.getPrice("apple", 12); 

     for (int i = 0; i < result.Length; i++) 
     { 
      Console.WriteLine(result[i]); 
     } 

    } 
} 
} 

它和預期的一樣,在控制檯中顯示我的字符串類型1,2。

任何人誰想要實現Axis Web服務的.Net客戶端消耗和

返回原始數據類型的列表

需要服務,可以參考我的情況。

雖然也有一些例子,其中輸出僅僅是一個原始的類型,而不是像通用

列表中的Java。