Home > flash builder, flex > Using Import Web Service wizard to connect Flex to .NET

Using Import Web Service wizard to connect Flex to .NET

July 28th, 2008

Since I was deeply involved in Flex Builder support for working with .NET I thought that it would be a good idea to write some articles on how you can use these technologies together. I will create a “Hello World” project but the focus will be on how you can better make use of the available tools.

For tooling I will be using Flex Builder and Visual Web Developer 2008 Express Edition (VWD).

First let’s create a simple ASP.NET Web Service project using VWD:


I slightly modified the HelloWorld method in Service.cs to receive a parameter:

public string HelloWorld(String name) {
    return "Hello " + name + "! Nice talking to you!";

Now let’s get into Flex Builder and try to get something from the .NET Server. First we will create a new Flex Project on top of the .NET one. To do that click on New->Flex Project and choose ASP.NET as the server technology:


Make sure the location is the same as the VWD .NET project. Now run the default MXML file to start the ASP.NET Developer Server.

Next we will generate the glue code for calling the Web Service using the Import Web Service Wizard. Choose Data -> Import Web Service (WSDL) from the Flex Builder menu. On the first page the main source folder is selected by default. You can leave it like this. On the second page you need to choose the WSDL URI. When you launched the MXML application the ASP.NET Developer Server should have started by default on port 3000 (see the tray icon). In this case the WSDL URL should be something like http://localhost:3000/testDotNet/Service.asmx?WSDL.


The third page should look like this:


Now you should have some typed AS classes that provide easy access the .NET Web Service methods. The cool thing about this is that Flex Builder knows now how to do autocompletion on Web Service calls. So making a little application that will showcase this is just too easy:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
            import mx.controls.Alert;
            import generated.webservices.HelloWorldResultEvent;
            import generated.webservices.Service;
            public function sayHello():void {
                var service:Service = new Service();
                    function (event:HelloWorldResultEvent):void {
    <mx:TextInput x="176" y="171" id="myName"/>
    <mx:Text x="70" y="173" text="Enter Your Name"/>
    <mx:Button x="344" y="171" label="Click to receive greeting" click="sayHello()"/>

Categories: flash builder, flex Tags:
  1. Hugues
    November 29th, 2008 at 08:50 | #1

    Excellent! Thanks :)

  2. Sumendra Kumar
    December 10th, 2008 at 23:12 | #2

    Cool Title…really helped me…

  3. Brian
    March 20th, 2009 at 11:55 | #3

    Any chance of you creating an example of binding a flex datagrid the same way? Better yet, an editable datagrid?

    Thanks for this example! You rock!

  4. June 1st, 2009 at 14:15 | #4

    Sweet man, i couldnt figure out why my project didnt work thanks to this simple example i understood why =P


  5. August 19th, 2009 at 19:03 | #5

    excellent example!!

  6. Amol
    September 10th, 2009 at 00:11 | #6

    I tried this and no alert box poped up so I added a “FaultEventListener” to see what the error was. This is what I saw:

    [RPC Fault faultString="Security error accessing url" faultCode="Channel.Security.Error" faultDetail="Destination: DefaultHTTP"]

    I have the .Net web service and my Flex application on my local machine. The web service uses Anonymous access for authentication.

    Any ideas?

  7. Amol
    September 10th, 2009 at 00:32 | #7

    OK, I found the issue. The stubs created from the WSDL had the default URL set to “http:///….” instead of “http://localhost/…..”

    Changing it to localhost solved my problem and I can get back the data from the web services.

  8. Lalit
    November 16th, 2009 at 16:10 | #8

    This works fine on my development machine, but fails on production server.
    Where i can change the web service url in flex bin.

    i have placed the whole flex bin folder, in .net web application and placed the object tag on aspx page, swf is being loaed properly but generate fault everytime calling the web service.

    could you give me some link where i can learn the deployment of this type of application?

  9. Rose
    January 26th, 2010 at 02:59 | #9


    I am having a strange issue – when I try to import a web service locally, it finds the service, but does not show me any methods. When I import a service running on the dev server, I see the methods, but get an error: Provider com.bea.xml.stream.MXParserFactory not found.

    Any suggestions? Thanks in advance.

  10. Rovline
    March 22nd, 2010 at 16:14 | #10


    Uri TryPostUrl {
    get {
    if (postUrl == null) {
    if (HttpPostOperationBinding == null) return null;
    Port port = FindPort(HttpPostOperationBinding.Binding);
    if (port == null) return null;
    HttpAddressBinding httpAddress = (HttpAddressBinding)port.Extensions.Find(typeof(HttpAddressBinding));
    HttpOperationBinding httpOperation = (HttpOperationBinding)HttpPostOperationBinding.Extensions.Find(typeof(HttpOperationBinding));
    if (httpAddress == null || httpOperation == null) return null;
    postUrl = new Uri(httpAddress.Location + httpOperation.Location);
    postUrl = new Uri(myAdress + httpOperation.Location);
    return postUrl;


    > postUrl = new Uri(myAdress + httpOperation.Location);


    string myAdress = httpAddress.Location;
    myAdress = myAdress.Replace(“localhost”, “anydomain”);
    postUrl = new Uri(myAdress + httpOperation.Location);

  11. samruddhi.
    March 26th, 2010 at 12:05 | #11


    this is my first flex application and i m trying to make a login form using wsdl. My wsdl return string called “Success” if the user name and password is correct.
    I call the web service at the click of submit button
    when i try to get the return value into a variable for eg:

    var info:String = service.lastResult

    i always get a null value at first. When i click for the second time, it returns the string.
    I m not able to understand. Please help.

    Thanks in advance,

  12. H
    June 1st, 2010 at 17:06 | #12

    Hi Samruddhi,

    I am also facing the same issue. Were you able to resolve the problem you were facing.



  13. October 20th, 2011 at 14:17 | #13

    I am having a strange issue – when I try to import a web service locally, it finds the service, but does not show me any methods. When I import a service running on the dev server, I see the methods, but get an error: Provider com.bea.xml.stream.MXParserFactory not found.

Comments are closed.