How to call asp.net webservice from flex

In this article you will learn how to call webservices hosted on asp.net applications from flex. Create a web service on asp.net that returns the list of records. Here is how to create web service in asp.net Asp.net web service.

Create webservice.

		public class WebService :  System.Web.Services.WebService

{

public  WebService()

{

//Uncomment the following line if using designed components

//InitializeComponent();

}

[WebMethod]

public List GetItems()

{

return DotGalleryController.GetItems(-1);

}

[WebMethod]

public int AddItems(string Title, string  ShortDescription, string Description, string ImageUrl, string Author)

{

GalleryItemInfo item = new GalleryItemInfo();

item.Title = Title;

item.ShortDescription =  ShortDescription;

item.Description =  Description;

item.ImageUrl = ImageUrl;

item.EntryDate = System.DateTime.Now;

item.Author = Author;

DotGalleryController.AddItem(item);

}

} 

Now its time to call webserivce from flex application. Create mx:Webservice object and operations.

		



 

Now create the methods to handle webservice events.

		private  function initApp():void

{

webService.GetItems();

}

private  function getItems_result(evt:ResultEvent):void {

Alert.show("Result  came!");

moviesList.dataProvider = evt.result;

}

private  function getItems_fault(evt:FaultEvent):void {

Alert.show(evt.type);

}
 

Create a  databound control to show the results.

		

















 

Like us

See also