Flex AS3 Webservice Proxy and Object Binding

Flex AS3 Webservice Proxy and Object Binding


Introduction

In the previous article we see how a flex as3 can call webservice simply by using the Webservice class.
Let's see about webservice resultformat and data binding.

The Webservice Client Result Format in AS3

The webservice client result format can be "Object, xml, or e4x".

  • The Object(default resultFormat) return data in form of ObjectProxy. ObjectProxy contains different datatypes like ArrayCollection etc. You would have to handle and parse this result obtaining the data you expect.
  • XML format returns the data as an array of XMLNodes.
  • E4X format gives an XMLList. 



But like jax-ws java client maked with netbeans wizard I wish to search about automatic data binding.

It shows how make the proxy objects by using the wsdl.
This is done by flex builder ide.

Import Webservice into flex builder

The following link show the detailed steps

I write only some notes about this.
First of all, Import webservice inside flex builder project:

Data Menu -> Import Webservice and so on.

Then in order to call the webservice use the

NameService class.
Where Name is the name of webservice.

var ws:NameService = new NameService();

The autogenerate procedure make also one listener for each operation inside the webservice.
So add the listener and make the proper function called by the listener

ws.addOperation1EventListener(onResultOperation1);

the onResultOperation1 definition is like this:

private function onResultOperation1(res:Operation1ResultEvent):void
{
   var value:Operation1ReturnType = res.result._return;
}

The Operation1ResultEvent and Operation1ReturnType is created by flexbuilder during the webservice import.
Note that Operation1ReturnType is the real return type used also in the webservice (server side).
So in this function you obtain directly the returnType Object.

Ok, for calling the webservice, first assign the request variable.

//inside costructor possible parameter to be pass to the webservice //operation
var param:Operation1_request = new Operation1_request(); 
ws.Operation1_request_var = param;

call it

ws.Opearation1_send();


Conclusion

In this way more coding works is done automatic by the ide.

1 comment:

Anonymous said...
This comment has been removed by a blog administrator.