Monday, October 02, 2006 c# webservice consumed by flex

Someone on the flexcoders asked to be provided with a simple example of flex consuming an webservice. I know this might be VERY simple, but it proves functionality.

ASP.NET Webservice in C#

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;

namespace Director
public class Hello : System.Web.Services.WebService
public Hello()
{ InitializeComponent(); }

#region Component Designer generated code

private IContainer components = null;
private void InitializeComponent() { }

protected override void Dispose( bool disposing ) {
if(disposing && components != null)

public string HelloWorld(string variable) {
return "Hello " + variable;

Flex Application:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="" layout="absolute">
<mx:WebService id="myService"

<mx:Label text="{myService.HelloWorld.lastResult}"/>

If you're accessing a webservice on another machine or domain, don't forget the crossdomain.xml file in the IIS root:
<?xml version="1.0"?>
<!-- -->
<allow-access-from domain="*"/>


Anonymous said...

Is this for Flex Builder 2?

Victor Rubba said...

The Flex Application is done in Flex Builder 2. The .net part is done in Visual Studio 2003

Elton Bicalho do Carmo said...

Very useful example.

It will be very good with you write more about Flex and C# webservices.

I suggest you to leave a link with source code for download.

Keep the good work up.

Thanks to share you talent with us.

Anonymous said...

Easy and simply example. Thanks for the quick tutorial.

Alkan ARSLAN said...

Realy Easy and simply example. Thanks :)