views:

549

answers:

3

I have a dynamic Class that is a Value Object that is used to pass arguments to a WebService. It has two public properties:

package
{
    [Bindable]
    public dynamic class WebServiceCriteria
    {
        public var property1:String;

        public var property2:String;
    }
}

I set these two properties in one part of my application:

var myCriteria:WebServiceCriteria = new WebServiceCriteria();

myCriteria.property1 = "x";

myCriteria.property2 = "y";

Then I added other - dynamic - properties at another point in my application:

myCriteria.property3 = "z";

However, when I pass the instance to the WebService as the arguments, the original two public properties are not sent (as I can see in Fiddler), even though they have values. But, I can see them as properties of my Class instance in the debugger just prior to the send().

operation.arguments = {args: myCriteria};

operation.send(); // only property3 is sent

Why are those two properties not sent?

Here is an example of the SOAP request sent to the WebService:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
  <SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"&gt;
    <intf:webservice_controller xmlns:intf="http://childDir.parentDir"&gt;
      <args xsi:type="apachesoap:Map" xmlns:apachesoap="http://xml.apache.org/xml-soap"&gt;
        <item>
          <key xsi:type="xsd:string">property1</key>
          <value xsi:type="xsd:string"></value>
        </item>
        <item>
          <key xsi:type="xsd:string">property2</key>
          <value xsi:type="xsd:string"></value>
        </item>
        <item>
          <key xsi:type="xsd:string">property3</key>
          <value xsi:type="xsd:string">z</value>
        </item>
      </args>
    </intf:webservice_controller>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
+1  A: 

Try to add this to your constructor :

package
{
    [Bindable]
    public dynamic class WebServiceCriteria
    {
        public var property1:String;
        public var property2:String;

        function WebServiceCriteria()
        {
             prototype.property1 = null;
             prototype.property2 = null;
        }
    }
}

... As it seems like only the Objects properties are enumerable

Theo.T
+1  A: 

This behavior is documented in Flex 3.0 manuals. See Dynamic Classes for more information. A direct quote:

[...]Methods created in this way, however, do not have access to any private properties or methods of the [example] class. Moreover, even references to public properties or methods of the [example] class must be qualified with either the this keyword or the class name.

dirkgently
A: 
smartdirt
Really? I've done it this way many times. Flex converts it to an associative array in the SOAP request without a problem, and my CFC accepts it as a struct (see example above).
Eric Belair