来自Axis2 Web服务的OMElement的C#客户端

时间:2013-01-05 10:15:13

标签: c# axis2 axiom

我有一个使用AXIOM实现的Axis2 Web服务,它返回一个String列表。

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”,WAS中axis2.xml中的配置设置为

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

我可以处理单个String响应。

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

我搜索了类似案例

但看起来我不会遇到这种情况。

你有什么想法吗?

1 个答案:

答案 0 :(得分:0)

搜索时间导致了一些不使用AXIOM的解决方法,但基于POJO

网络服务。

这是返回String of List的服务。

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));
}
}

在.Net项目的Reference.cs中,我添加了

[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 retVal.@return;
    }

    [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#中使用Generic中的List或ArrayList。

返回值是字符串数组。 - &GT; (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,它按预期工作。

任何想要实施.Net客户端和

所使用的Axis2 Web服务的人

需要返回原始数据类型List的服务,可以参考我的情况。

虽然有一些例子,其中输出只是一种原始类型,而不是Generic,如

用Java列出。