views:

1413

answers:

3

Two of our apps are web applications with a Flex 3 front end and a SOAP-style WCF back end. To communicate with the back end, I generate web service client classes through Flex Builder 3. Everything's functional, but maintaining those generated classes has been quite annoying, and I'm looking for a better way to do things (without having to do a major rewrite, of course). Here's the problems:

  1. I use Flex libraries to manage components shared among applications. Some of them are dependent on the generated classes, so I need the WSDL-generated classes in their own library. Flex Builder 3, however, only generates the classes for a Flex application, so I have to generate the files in the application's source tree, then manually move the files every time. This also introduces strange side-effects with the way that Eclipse manages source code (why can't it just monitor the FS like other IDEs do?).
  2. We use data binding in the MXML to declaratively tie data to the UI. I like data binding. Unfortunately, the classes in the WSDL-generated code do not support binding. Therefore, I opted to create a program to alter the ActionScript classes, adding [Bindable] metadata to them. This has to be run every time we regenerate the code.
  3. Flex has a very nasty bug, known about at least since March, which still hasn't been fixed: http://bugs.adobe.com/jira/browse/SDK-19811. I recently discovered this, because it was double-encoding some XML characters like < and & into < and &. Therefore, I also had to add a workaround for that to the ActionScript manipulation program.
  4. The WSDL-code generator in Flex Builder creates a String, Boolean, Int, and other classes which are built-in types! We're always having to delete these source files to prevent the Flex compiler from sometimes balking.

It seems unlikely to me that everyone is just putting up with these issues. There must be some alternative way of generating web service proxy classes for Flex that others are employing. Since I'm time-prohibited from making the communication layer RESTful and rewriting the front end in Silverlight, what do you suggest?

+1  A: 

You can use one of several mechanisms to read the WSDL into a program and generate whatever flex code you need.

  1. You can use one of the two ServiceDescription classes to read in a WSDL and examine its contents in terms of an object model;
  2. You can use T4 Templates in Visual Studio with a bit of custom work to expose the WSDL to the template (possibly through the ServiceDescription class, as above)
  3. You can use XSLT to transform the WSDL into the code you'd like
  4. You can write some standalone program to read the WSDL (as XML or an object model) and just emit the text you want for your proxy code.

The bottom line is that, if you're having problems with the automation tools, then there are practical ways of creating your own.

John Saunders
A: 

I'm a Flex Developer having the exact same problem as described above. I'm importing a wsdl WebService from ASP into Flex and need the generated AS classes to have the [Bindable] metatag above public class . I cannot find any other topics that become so close to the answer as is this one, but I cannot solve it with the provided answer.

Can anyone post some extra information or sample code on this topic whereas it's driving me nuts that something so simple (just adding a [Bindable] metatag to a generated class) is holding me back so long.

Erik
A: 

Unfortunatly Flex 3 code generation from WSDL lacks from the Bindable tag, and it is a nightmare to handle that problem manually... especially if you have a complex scenario with lots of Types.

You could just add the tag manually and remove the "generated.webservices" from all variable declarations in order to make the code compile... and then you have another problem:

What if i have to generate de code again? Either i do everything again... or i will have a bunch of runtime only detected bugs...

I used ANT to a small trick:

Add Bindable to all classes; Remove the full namespace from all variable declarations;

<target name="updateGeneratedCode" >
    <replace dir="PATH TO YOUR GENERATED CODE">
        <include name="**/*.as"/>
        <replacetoken>public class</replacetoken>
        <replacevalue><![CDATA[[Bindable]public class]]></replacevalue>   
    </replace>

    <replace dir="PATH TO YOUR GENERATED CODE" value=":">
        <include name="**/*.as"/>
        <replacetoken>:generated.webservices.</replacetoken>
    </replace>
</target>

Note: the replace token ":generated.webservices." may be different in your case, so you may want to replace it by your generated namespace.

It is working for me so far.

Hope it helps someone!

Antonio Inacio

António Inácio
i posted the ant rule but it is not showing :P
António Inácio
<target name="updateGeneratedCode" > <replace dir="PATH TO YOUR GENERATED CODE"> <include name="**/*.as"/> <replacetoken>public class</replacetoken> <replacevalue><![CDATA[[Bindable] public class]]></replacevalue> </replace> <replace dir="PATH TO YOUR GENERATED CODE" value=":"> <include name="**/*.as"/> <replacetoken>:generated.webservices.</replacetoken> </replace> </target>
António Inácio
Probably the the xml markup messed with the post...
António Inácio
Indent code with 4 spaces to have it displayed as code in SO (fixed)
Jacob