Calling Web service from Flex – Part 1

Here I am Explain how to use Web Services in Flex Application.


1) First we create web service in with C#. create new Web method in Web service is GetName.

    public string GetName(string UserName)
        return "WelCome  " + UserName;

My web service name is WebServices.

using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
/// <summary>
/// Summary description for WebService
/// </summary>
[WebService(Namespace = "")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebService : System.Web.Services.WebService {

    public WebService () {

        //Uncomment the following line if using designed components 
    public string HelloWorld() {
        return "Hello World";
    public string GetName(string UserName) {        
        return "WelCome  " + UserName;

2) Open Flex Application.

3) Put below control in to application.

    3.1)  WebService (ID =MyWebService)

    3.2) Label for display Information

    3.3) TextArea (ID=txtUserName) – get value and pass value in to WebService

    3.4) Button (ID=btnSubmit) – Call Web service

    3.5) TextArea (ID=txtResult) – Display result from Web service

Application Page Info.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="" layout="absolute">
<!--Web Service Information 
wsdl  URL of Web Service
fault  if any error loading web service
operation  method name in Webservices
request  pass the parameter to Webservices
*here I get the TextBox Value 
<mx:WebService id="MyWebService" wsdl="http://localhost:3549/ChangeWebConfigFile/WebService.asmx?WSDL"
    fault="" >
    <mx:operation name="GetName">

    <mx:Label text="Enter User Name">        
    <mx:TextArea id="txtUserName" text="test">        
    <mx:Button id="btnSubmit" label="Submit.." click="checkUserName();">        
    <mx:TextArea id="txtResult"/>    
      private function checkUserName():void
        txtResult.text= MyWebService.GetName.lastResult;            

4) Run Flex Application.








  1. nice article..

  2. Very helpful document for flex learners and beginners..

  3. youre about the only person Ive seen in about the past six or so nights that actually checks their code before they post it. Man, is it just me or are the vast bulk of online tutorials these days just junk posted for a laugh or something?

    1. I am not getting you…

  4. i run the application i get a error message “Security error accessing url”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s