0

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

有效的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() );
    }

我需要实现使用上述服务的 ac# 客户端。

我已经能够测试返回单个 String 对象的 ac# 客户端,如下所示。

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>

我可以处理单个字符串响应。

但我不知道如何处理上面的字符串列表。

我搜索过类似的案例

但看起来我没有遇到这种情况。

你有什么主意吗?

4

1 回答 1

0

经过数小时的搜索,我们找到了一些解决方法,其中不使用 AXIOM,而是基于 POJO

网络服务。

这是返回字符串列表的服务。

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。

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

任何想要实现 Axis2 Web 服务以供 .Net 客户端和

需要返回原始数据类型列表的服务,可以参考我的案例。

虽然有些例子中输出只是一个原始类型,而不是像 Generic 这样的

用 Java 列出。

于 2013-01-06T11:01:47.017 回答