0
votes

I have a Axis2 web service implemented using AXIOM that returns a list of String.

The code snippet of client in Java that works is as follws.

   // * 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() );
    }

I need to implement a c# client that consumes the service as above.

I've been able to test a c# client that return a single String object as below.

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

The message type in app.config is "MTOM" and the configuration in axis2.xml in WAS is set to

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

I can deal with a single String response.

But I have no idea how to deal with a list of String as above.

I've searched the similar cases

but it looks like there is not the case I am faced with.

Do you have any idea?

1

1 Answers

0
votes

Hours of searching has resulted in some workaround in which AXIOM is not used, but POJO-based

web service.

Here comes the service that return a List of String.

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

And in Reference.cs in .Net project, I added

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

If you look at the code, I did not use List or ArrayList in Generic from C#.

Return value is string array instead. -> ( public string [] getPrice(string symbol, int number) )

And the c# client code goes like below.

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

    }
}
}

And it worked as expected by showing me 1, 2 in string type in console.

Anyone who want to implement Axis2 web service to be consumed by .Net client and

needs service that returns a List of primitive data type, may refer to my case.

Although there are some examples in which output is just a primitive type, not Generic like

List in Java.