4 Replies Latest reply on Aug 27, 2010 3:37 AM by TB_DK

    Using SOAP service in FLEX 4


      Dear all,


      I'm new to FLEX and AS but as usual there are some task to do and unfortunately I can not start from scratch with FLEX (looking forward to do this in my leisure times).


      I created a simple SOAP service where I have a method:


          public String Hello(String lcname)
              return "Hello " + lcname;


      I bind the service to the FLEX project, drop a TextInput, a button and a label into the application and pull the service onto the button. Now I would like to have the functionality that the user can write his name into the textinput, press the button and the label will show 'Hello foo', where foo is the stuff the user wrote into the textinput. I do not know how to get this done...


      protected function button_clickHandler(event:MouseEvent):void
                      HelloResult.token = service.Hello(inName.text);
                      outName.text = HelloResult.token.result.toString();

      This doesn't work in FLEX and comes with:


      TypeError: Error #1009: Cannot access a property or method of a null object reference.
          at newService/button_clickHandler()[C:\Documents and Settings\thob\Adobe Flash Builder 4\newService\src\newService.mxml:21]
          at newService/__button_click()[C:\Documents and Settings\thob\Adobe Flash Builder 4\newService\src\newService.mxml:43]


      Could you give me a simple example how to get it to work? Thanks, Thomas

        • 1. Re: Using SOAP service in FLEX 4
          fleRavix Level 2

          Did it work in Flex 4?

          • 2. Re: Using SOAP service in FLEX 4
            TB_DK Level 1

            I'm able to use the service for e request on a database and it turns the message correct back but my stuff with the Hello function doesn't work.

            • 3. Re: Using SOAP service in FLEX 4
              fleRavix Level 2

              FLEX PART

              Take new project ...


              <?xml version="1.0" encoding="utf-8"?>

              <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"


                 xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">




              import mx.controls.Alert;

              import mx.rpc.events.ResultEvent;


              import services.helloservice.HelloService;


              protected function button1_clickHandler(event:MouseEvent):void


              // TODO Auto-generated method stub

              var hs:HelloService = new HelloService();





              private function onServiceResult(event:ResultEvent):void








              <!-- Place non-visual elements (e.g., services, value objects) here -->


              <s:TextInput x="119" y="147" width="277" id="txtInput"/>

              <s:Button x="119" y="172" label="SEND" width="128" click="button1_clickHandler(event)"/>

              <s:Label x="68" y="152" text="Name :&#xd;&#xd;"/>




              .Net part :

              Create new SASP.NET WEBSERVICE with C# as language


              using System;

              using System.Linq;

              using System.Web;

              using System.Web.Services;

              using System.Web.Services.Protocols;

              using System.Xml.Linq;


              [WebService(Namespace = "http://tempuri.org/")]

              [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

              // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.

              // [System.Web.Script.Services.ScriptService]

              public class Service : System.Web.Services.WebService


                  public Service () {


                      //Uncomment the following line if using designed components





                  public string HelloWorld() {

                      return "Hello World";




                  public string sayHello(string strName)


                      return "Hello " + strName;




              Mark this if useful
              1 person found this helpful
              • 4. Re: Using SOAP service in FLEX 4
                TB_DK Level 1

                Thx fleRavix I will have a look into it. However, how it comes that I have to import the service to get this to work while I can use the service without importing it when I want to populate a datagrid with data from a database, provided via the SOAP service?


                Cheers Thomas