0

I wanted to use some amfphp functions in .NET and get access to some objects. After some searching I found a piece an opensource gateway that would do the trick. How to use AMFPHP functions from .NET WPF application?

Ok here is were I am right now , and I could really use some help. After having made the connection and proper calls

  public void Connect()
        {
            // Create NetConnection client
            _netConnection = new NetConnection();
            _netConnection.ObjectEncoding = ObjectEncoding.AMF0;
            _netConnection.NetStatus += new NetStatusHandler(_netConnection_NetStatus);
            _netConnection.Connect("http://www.mytestserver.nl/services/gateway");

            System.Console.WriteLine("*** Flash RPC ***");
            _netConnection.Call("amfphp.mytestserver.getObjects", new GetCustomersHandler(), new object[] { "415" });

            System.Console.WriteLine("Press 'Enter' to exit");
        }

And in my handler

  public class GetCustomersHandler : IPendingServiceCallback
    {
        public void ResultReceived(IPendingServiceCall call)
        {
            object result = call.Result;
            System.Console.WriteLine("Server response: " + result);

            //DataAccess sample sends back an ArrayCollection (AMF3)
            ArrayCollection items = result as ArrayCollection;


            foreach (object item in items)
            {
                Flex.CustomerVO customer = item as Flex.CustomerVO;
                System.Console.WriteLine(customer.firstname + " " + customer.lastname);
            }
        }
    }

This is the way it is done in the project given in the samples folder. I cannot iterate through the items , so I figured let me see how I can access my results object. And here is were is it (at least for me) getting a bit tricky. I can see the results as type object in my list , I can access the result array (?object) , but how do I iterate through my results objects in code since it is not an array. To clarify I added some screenshots.

http://imageshack.us/f/685/fluorine1.png/ as can be seen here results containing 46 items.

a little more clarification http://imageshack.us/f/38/fluorine2.png/ (For instance I wish to access the Key, Value and such). Does anyone have a solution or approach. It doesn't feel difficult(perhaps it is) but I seem to missing something. Some help anyone?

Community
  • 1
  • 1
Shinji
  • 85
  • 1
  • 11

2 Answers2

0

It is indeed an array. It is an array of objects (object[]). You can access this like is shown in the example. The only problem is that you have to know what kind of object it is and cast it to that type.

Flex.CustomerVO customer = item as Flex.CustomerVO;

is where they cast the object.

jle
  • 9,316
  • 5
  • 48
  • 67
0

If you want to iterate over the objects, you need to cast your result to an array of objects:

object[] objects = (objects)result;

Then you can access the individual items by casting again:

foreach (object obj in objects)
{
    FluorineFx.ASObject asObject = (FluorineFx.ASObject)obj;
    System.Console.WriteLine(asObject.Key);
}
Daniel Sklenitzka
  • 2,116
  • 1
  • 17
  • 25