Hi all.
.NET DataSets can be sent from .NET web services to populate Flex
objects (and be bound to controls such as datagrids), and that Flex
1.5 can send Arrays to .NET, where they are seen as
DataTables inside DataSets.
You just have to use .NET typed datasets.
The only problem I found so far is the one I started this thread
(i.e. the fact that Flex arrays are serialized as <item> elements,
so that the resulting .NET DataSet contains a DataTable
named "item").
Here is a sample that shows how to send a Flex datagrid to a .NET
web service.
---------------- .NET ---------------------
This is a .NET web method that accepts a DataSet:
[WebMethod]
public int InOutVipTypedDataset(VipDS InputVP)
{
return 1;
}
VipDS is a typed dataset (in visual studio, create it with Add->New
Item->Dataset). Name the resulting schema VipDS.xsd. It just
contains a single table with two columns (name and surname).
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="VipDS"
targetNamespace="http://www.xylabs.net/webservices/VipDS.xsd"
elementFormDefault="qualified"
attributeFormDefault="qualified"
xmlns="http://www.xylabs.net/webservices/VipDS.xsd"
xmlns:mstns="http://www.xylabs.net/webservices/VipDS.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="VipDS" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="VipDT">
<xs:complexType>
<xs:sequence>
<xs:element
name="name" type="xs:string" minOccurs="0" />
<xs:element
name="surname" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
---------------- FLEX ---------------------
This is the flex side. This sample is unnecessary complicated (the
web service parameters are bound to a model, whose contents are
populated at runtime with a script, but more simply the model could
be bound to an editable datagrid, for instance).
<mx:WebService id="SimpleWebService"
wsdl="http://myservername/myvirtualdirectory/Service.asmx?WSDL"
fault="mx.controls.Alert.show(event.fault.faultstring)"
showBusyCursor="true">
<mx:operation name="InOutVipTypedDataset"
result="handleInOutVipTypedDataset(event)">
<mx:request>
<InputVP>{DGM2.InputVP.Vip}</InputVP>
</mx:request>
</mx:operation>
</mx:WebService>
<mx:Model id="DGM2">
<InputVP><Vip/></InputVP>
</mx:Model>
<mx:Script>
<![CDATA[
private function send():Void {
import vo.Vip;
var arr:Array;
arr = new Array();
var v:Vip = new Vip();
v.name="Peter";
v.surname="Pan";
arr.push(v);
v=new Vip();
v.name="Capitain";
v.surname="Hook";
arr.push(v);
DGM2.InputVP.Vip=arr;
SimpleWebService.InOutVipTypedDataset.send();
}
]]>
</mx:Script>
<mx:Button label="Send DataSet" click="send()"/>
-----------------------------------
The following defines the Value Object used in the above script.
Just save it to a file named Vip.as in a directory called vo:
class vo.Vip {
var name:String;
var surname:String;
}
-----------------------------------
When you press the "send" button, the array of Vip objects is sent
to the .NET web service. If you hook the visual studio debugger to
the running instance of the web service, you can see that the
InputVP DataSet contains a datatable named "item" (this is due to
the way Flex serializes the array - see the start of the thread and
let me know if you can correct it), whose columns are "name"
and "surname".
On the way back (.NET to Flex), things are easier. When you send a
typed (or even non-typed) dataset from .NET to Flex, it can be
accessed inside the result object.
This is not required, but I like to give my dataset a name in .NET:
DataSet ds = new DataSet("MyDataSet");
then I can access it in Flex (and bind it to a datagrid or whatever)
using this syntax:
MyWebService.MyWebMethod.result.diffgram.MyDataSet.MyDataTable
where:
- MyWebService is the id of your "mx:WebService" Flex control
- MyWebMethod is the name attribute of your "mx:operation" element
- MyDataSet is the name of your dataset (or NewDataSet if you didn't
give it a name)
- MyDataTable is the name of one of the datatables contained in your
dataset
Sample usage:
<mx:Repeater id="rep"
dataProvider="{MyWebService.MyWebMethod.result.diffgram.MyDataSet.MyD
ataTable}">
<mx:Label text="{rep.currentItem.ColumnName1}"/>
<mx:Image source="{rep.currentItem.ColumnName2}"
</mx:Repeater>
Hope this can be useful.
BTW, today my trial Flexbuilder license has expired once again....
and it seems I can't buy it on the Macromedia store because it's not
listed. I've already got an extension serial from the Macromedia
customer care, but it required some time and frustration. Matt,
can you help? My company is seriously interested in Flex.
bye
fabio
------------------------ Yahoo! Groups Sponsor --------------------~-->
Get Bzzzy! (real tools to help you find a job). Welcome to the Sweet Life.
http://us.click.yahoo.com/KIlPFB/vlQLAA/TtwFAA/nhFolB/TM
--------------------------------------------------------------------~->
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/