Using a web service

I’m trying to use a web service I created but it’s not working. I’m pretty sure I’m doing it all wrong but all the tutorials I found are much more complicated than what I need and I don’t have much Flex/AS experience.

So the web service I created simply returns a string and I’d like to assign that string to a variable. Here’s the code I’m using:

 
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" xmlns:text="flash.text.*" applicationComplete="loadList();">
 <mx:Label id="txtTest" />
 <mx:Script>
  <![CDATA[
 
         import mx.rpc.soap.WebService;
         import mx.rpc.events.ResultEvent;
         import mx.rpc.events.FaultEvent;
 
         private var ws:WebService;
         public var resultStr:String;
 
         public function loadList():void
         {
           ws = new mx.rpc.soap.WebService();
           ws.destination = "https://secure.mojointeractive.com/Flex/Quote.cfc?wsdl";
           ws.getToParseList.addEventListener("result", updateParseList);
           ws.addEventListener("fault", faultHandler);
           ws.loadWSDL();
           ws.getToParseList();
         }
 
         private function updateParseList(event:ResultEvent):void
         {
           resultStr = event.result.echoStr;
           txtTest.text = resultStr;
         }
 
         private function faultHandler(event:FaultEvent):void
         {
           txtTest.text = "Error: " + event.fault.faultString;
         }
  ]]>
 </mx:Script>
</mx:WindowedApplication>

Any help would be greatly appreciated.

I forgot to add the error message I’m getting:

[MessagingError message=‘Destination ‘https://secure.mojointeractive.com/Flex/Quote.cfc?wsdl’ either does not exist or the destination has no channels defined (and the application does not define any default channels.)’]

Thanks again for any advice.

I made some progress in the mean time but it still doesn’t work. Now I’m getting this error:

[RPC Fault faultString=“SOAP Response cannot be decoded. Raw response: testing1.3” faultCode=“DecodingError” faultDetail=“null”]

Here’s my new code:

 
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" xmlns:text="flash.text.*" applicationComplete="loadList();">
 <mx:TextArea id="txtTest" width="100%" height="100%" />
 <mx:Script>
  <![CDATA[
 
   import mx.rpc.soap.WebService;
   import mx.rpc.events.ResultEvent;
   import mx.rpc.events.FaultEvent;
 
   private var ws:WebService;
   public var resultStr:String;
 
   public function loadList():void
   {
     ws = new mx.rpc.soap.WebService();
     ws.getToParseList.addEventListener("result", updateParseList);
     ws.addEventListener("fault", faultHandler);
     ws.loadWSDL("https://secure.mojointeractive.com/Flex/Quote.cfc?wsdl");
     ws.endpointURI = "[https://secure.mojointeractive.com](https://secure.mojointeractive.com/)";
     ws.getToParseList("a");
   }
 
   private function updateParseList(event:ResultEvent):void
   {
    resultStr = event.result.toString();
    txtTest.text = resultStr;
   }
 
   private function faultHandler(event:FaultEvent):void
   {
    txtTest.text = "Error: " + event.fault.toString();
   }
  ]]>
 </mx:Script>
</mx:WindowedApplication>

I’ve created this ColdFusion script to make sure the Web Service works and it does return the string I’m looking for.

 
<cfinvoke webservice = "https://secure.mojointeractive.com/Flex/Quote.cfc?wsdl"
  method = "getToParseList"
  AccessCode = "a"
  returnVariable = "foo">
 
<cfoutput>#foo#</cfoutput>

Any help would be much appreciated.

It’s kind of sad that it’s so hard to do such a simple task (1 line in ColdFusion as I showed above). Anyways, I finally made it work but I still don’t know how or why the other codes didn’t work. Anyways, here’s the working code in case someone else needs to do the same thing:

 
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" xmlns:text="flash.text.*" applicationComplete="ws.getToParseList.send()">
 <mx:WebService id="ws"
  wsdl="https://secure.mojointeractive.com/Flex/Quote.cfc?wsdl"
  showBusyCursor="true">
  <mx:operation name="getToParseList"
    result="onResult(event)"
    fault="onFault(event)">
    <mx:request xmlns="">
     <AccessCode>a</AccessCode>
    </mx:request>
   </mx:operation>
  </mx:WebService>
 <mx:TextInput id="msg" x="681" y="10"/>
 <mx:Script>
  <![CDATA[
 
   import mx.rpc.events.FaultEvent;
   import mx.rpc.Fault;
   import mx.rpc.events.ResultEvent;
 
   private function onResult( e : ResultEvent ) :void
   {
    msg.text = e.result.toString();
   }
 
   private function onFault( e : FaultEvent ) :void
   {
    trace( 'Oops!' );
   }
  ]]>
 </mx:Script>
</mx:WindowedApplication>

Oh, when I said I fixed it, I meant I found a code online that works. Here’s the credits:

http://www.macmartine.com/blog/2008/04/flex_and_coldfusion_remoteobje.html

Wow, this is one lonely thread. Aight, I’m out.