1 Reply Latest reply on Jun 10, 2007 10:14 PM by mxc4

    How to avoid redeclaring your web service interface?

    mxc4
      Hi there,

      How can one avoid having to redeclare your wsdl interface on each mxml page where it is accessed? I only want to declare the web service and the operation is has once and then just include it in the component where I use it to access/update data.

      I am new to flex so this may be obviouse to other but not me. I tried including it in its own mxml file and then using the normal component include tag to include it. I get errors about not being able to access the webservice via its id.

      e.g.

      Error: Access of undefined property WebService.
      [mxmlc] WebService.getSiteOptions.send();


      thanks
        • 1. Re: How to avoid redeclaring your web service interface?
          mxc4 Level 1
          The solution is to place the web definition in a separate file and then use the "include" like functionality of defining your own namespace in the xml. You do the include in the main application file.

          eg
          <mx:Panel
          xmlns:mx=" http://www.adobe.com/2006/mxml"
          xmlns:webservice="webservice.*"
          width="100%"
          height="100%"
          title="Reports Menu"
          creationComplete="onInit();" >

          On the main application page to include your web service file do a

          <webservice:webservices id="services"/>

          The webservices.mxml file will contain your definitions.

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml"
          height="0"
          visible="false">

          <mx:Script>
          <![CDATA[
          import mx.rpc.soap.mxml.WebService;
          import mx.rpc.events.FaultEvent;
          import mx.controls.Alert;

          [Bindable]
          public var webServiceWSDL:String =" http://127.0.0.1:8080/jumpingbean/services/AddWebService?wsdl";
          public function onServiceFault(evt:FaultEvent):void
          {
          var err:Error = new Error(evt.fault.faultCode + " , " + evt.fault.faultString);
          parentApplication.showError(err);
          }

          public function onSuccess(evt:Event):void
          {
          Alert.show(evt.toString());
          }

          ]]>
          </mx:Script>

          <!-- ======================================== -->
          <!-- Remote Services -->
          <!-- ======================================== -->

          <mx:WebService id="webservice" wsdl="{this.webServiceWSDL}" service="ValueAddWebService" port="AppWebServiceHttpPort" fault="onServiceFault(event)" showBusyCursor="true" >

          etc

          In your child components you can refer to the component by doing a "parentApplication.services.webservice"