Flex and. Net WebService (continued: Collaborate with datatable)

Source: Internet
Author: User

. 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?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.