【问题标题】:C# client for OMElement from Axis2 web service来自 Axis2 Web 服务的 OMElement 的 C# 客户端
【发布时间】:2013-01-06 19:01:47
【问题描述】:

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

在Java中运行的客户端的代码sn-p如下。

   // * 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# 客户端。

我已经能够测试一个返回单个字符串对象的 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>

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

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

我搜索过类似的案例

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

你有什么想法吗?

【问题讨论】:

    标签: c# axis2 axiom


    【解决方案1】:

    经过数小时的搜索,找到了一些解决方法,其中不使用 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 中的列表。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-18
      • 2010-09-20
      • 1970-01-01
      • 1970-01-01
      • 2011-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多