. Net WebService often returns dataset data. Therefore, it is perfect if FLEX can process dataset. I thought this was a simple task, but I found the problem only after the test. Isn't flex working with. Net dataset?
No solution was found after searching the Internet. It is found that some people use structure arrays to return data, and some use XML strings to return data. Regardless of the method, it is inconvenient to make major changes to the existing. Net WebService.
Finally, we found that using datatable to return data can directly work with Flex.
Here is a simple example:
The following table is available:
Webmethod is getcustomer:
[WebService (namespace = " Http://tempuri.org/ " )]
Public Class Service: system. Web. Services. WebService
{
Public Service () {}
[Webmethod]
Public Datatable getcustomers () {
Dataset DS = New Dataset ();
Using (Sqlconnection Conn = New Sqlconnection ( @" Data Source = MUF \ sqlexpress; initial catalog = test; Integrated Security = true " ))
Using (Sqldataadapter ADA = New Sqldataadapter ( " Select * from customer " , Conn ))
{
Ada. Fill (DS,"Customer");
}
Return DS. Tables [ " Customer " ];
}
}
Now, just add <mx: WebService> to flex: <? XML version = "1.0" encoding = "UTF-8" ?>
< MX: Application Xmlns: MX = "Http://www.adobe.com/2006/mxml" Layout = "Absolute" Initialize = "Service. getcustomers. Send ();" >
< MX: WebService ID = "Service"
WSDL = "Http: // localhost: 1708/website1/service. asmx? WSDL"
Useproxy = "False" >
< MX: Operation Name = "Getcustomers" >
< MX: Request >
</ MX: Request >
</ MX: Operation >
</ MX: WebService >
< MX: DataGrid X = "25" Y = "10" Dataprovider = "{Service. getcustomers. lastresult. DiffGram. newdataset. Customer }" >
< MX: Columns >
< MX: datagridcolumn Headertext = "ID" Datafield = "ID" />
< MX: datagridcolumn Headertext = "Name" Datafield = "Name" />
< MX: datagridcolumn Headertext = "Address" Datafield = "Address" />
< MX: datagridcolumn Headertext = "Age" Datafield = "Age" />
< MX: datagridcolumn Headertext = "Gender" Datafield = "Gender" />
</ MX: Columns >
</ MX: DataGrid >
</ MX: Application >
The running result is as follows:
The binding value of dataprovider is service. getcustomers. lastresult. DiffGram. newdataset. Customer.
Newdataset is the name of dataset and customer is the name of the table.
Think: Why does dataset fail but the able row?