flash data integration:
I'm having a very frustrating time using the WebService class in Flash MX 2004. I have a functioning web service which passes my flash application an array of ComplexType objects. My flash file receives the Array fine, however, when I tried to access the objects within the array, they were showing up as undefined. On further inspection, I noticed that the SOAP markup was not being interpreted by Flash upon receiving the data. I did a trace on the first object of the array, and the raw XML was output. I did a little more investigating, and listed all the variables in my movie. It looks as though Flash is interpreting my objects as type XMLNode!! (the attached output shows this) Has anyone else experienced this problem and is there a solution? I guess I could fork my code and check whether the objects are XMLNodes, and then parse them manually, but this is a pain, and is unsettling since they should be parsed by WebService after arriving. lines:[object #893, class 'Array'] [ 0:[object #894, class 'XMLNode'] { <item xsi:type="SOAP-ENC:Struct"> <lineNum xsi:type="xsd:int"> 9 </lineNum> <winPositions SOAP-ENC:arrayType="xsd:int[2]" xsi:type="SOAP-ENC:Array"> <item xsi:type="xsd:int"> 2 </item> <item xsi:type="xsd:int"> 3 </item> </winPositions> <creditsWon xsi:type="xsd:float"> 1.5 </creditsWon> <symbolID xsi:type="xsd:int"> 2 </symbolID> </item> }, 1:[object #895, class 'XMLNode'] { <item xsi:type="SOAP-ENC:Struct"> <lineNum xsi:type="xsd:int"> 9 </lineNum> <winPositions SOAP-ENC:arrayType="xsd:int[2]" xsi:type="SOAP-ENC:Array"> <item xsi:type="xsd:int"> 2 </item> <item xsi:type="xsd:int"> 3 </item> </winPositions> <creditsWon xsi:type="xsd:float"> 1.5 </creditsWon> <symbolID xsi:type="xsd:int"> 2 </symbolID> </item> } ]
OK. Here's the problem, and the solution. The problem is caused by PHP and not by flash, so if you're struggling with this same problem, this solution should be of some help. Mad propz to D-bone for helping me with this solution. When using ComplexType in the schema portion of the WSDL file, you need use an additional step to tell PHP SOAP how to encode the objects. The first method would be to explicitely encapsulate the object in a SoapVar object - telling PHP to use generalized SOAP encoding rules (which encodes all ComplexTypes as Structs). This won't work, though, if the client is expecting the objects to be encoded according to the WSDL's schema. So, The actual way to do this is: First, define a specific PHP class which is actually just a data structure holding the various properties, and the appropriate ComplexType in the WSDL. class MyComplexDataType { public $myProperty1; public $myProperty2; } ... <complexType name="MyWSDLStructure"> <sequence> <element name="MyProperty1" type="xsd:integer"/> <element name="MyProperty2" type="xsd:string"/> </sequence> </complexType> Next, Tell the SoapServer when you initialize it to map these two structures together. $classmap = array('MyWSDLStructure' => 'MyComplexDataType'); $server = new SoapServer("http://MyServer/MyService.wsdl", array('classmap' => $classmap)) Finally, have your method return an instance of your class directly, and let the SoapServer take care of encoding! public function MySoapCall() { $o = new MyComplexDataType(); $o->myProperty1 = 1; $o->myProperty2 = "MyString"; return $o }
Don't see what you're looking for? Try a search.
|