Hi Graham,

 

I did not read your entire post, nor do I have any knowledge about cairngorm. But I’ll give a try ...

 

Your code: var tObj:TestObj = event.result as TestObj; will not work.

 

event.result is a dynamic Object and you cannot cast it to your own custom made ActionScript class TestObj. If you want to put the webservice result into an ActionScript object, you will have to do the following:

  • var tObj:TestObj
  • tObj = new TestObj();
  • tObj.Id = event.result.Id
  • tObj.Name = event.result.Name

 

Yep, it’s tedious and boring, but that’s exactly the way I’m doing it at the moment ...

 

On the other hand: it’s quite understandable. How can Flex know that the result coming back from a webservice is actually some sort of custom type? It would be an extremely interesting feature of Flex if you could specify that somehow ...

 

Cheers,

Franck

 


From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com] On Behalf Of grahampengelly
Sent: Tuesday, August 15, 2006 6:05 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Deserializing WebService call... Flex/Cairngorm

 

I am just getting up to speed with the Cairngorm architecture and have been struggling with this problem for a while. I have got to the point where I am getting a response from my web service call that has the data in that I expect but I cannot seem to get it to deserialize into the object that I need.

The code (I have used IResponder rather than the cairngorm Responder here as suggested during an earlier post here  )

        public function result( data:Object ):void
        {
             var event:ResultEvent = data as ResultEvent;
            
             var testString:String = "";
             for each(var thing:Object in event.result)
             {
                 testString += " " + thing + " ";
             }
             //test alert 1
             Alert.show(testString);
             //test alert 2
             Alert.show("event.result.Id = " + event.result.Id + ", event.result.Name = " + event.result.Name);
            
             var tObj:TestObj = event.result as TestObj;
             Alert.show("TestObj.Id = " + tObj.Id);
            
        }
The test alerts print out:
    test 1: Graham 1
    test 2: "event.result.Id = 1, event.result.Name = Graham

The subsequent line throws an exception:

TypeError: Error #1034: Type Coercion failed: cannot convert mx.utils::ObjectPro[EMAIL PROTECTED] to HASAW.ClientApp.Model.TestObj.

The object that I am trying to create from the results looks like this:

    public class TestObj implements ValueObject
    {
       
        public var Id:int;
        public var Name:String;
        public function TestObj()
        {
            Id = 0;
            Name = "";
        }
    }


I have tried various implementations and can't get the web service response to cast to TestObj. To be honest, I wouldn't have thought that it should cast to TestObj but I have followed all of the code samples for Cairngorm and they all do it like this.

I am using .NET for the web service which may be an issue as the samples don't. It is returning the following SOAP in event.result.body

  <?xml version="1.0" encoding="utf-8" ?>

-     <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>

-         <GetTesterResponse xmlns="">

-             <GetTesterResult>

                  <Id>1</Id>

                  <Name>Graham</Name>

          </GetTesterResult>

      </GetTesterResponse>

      </soap:Body>

  </soap:Envelope>


I know I could manually populate the object with the values but the objects I will be deserializing in the application are much more complex than this which would make a manual approach a pain.

Thanks in advance...

Graham

__._,_.___

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com





SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS




__,_._,___

Reply via email to