# Using a web service

**URL:** https://forum.kirupa.com/t/using-a-web-service/263479
**Category:** flash
**Created:** [June 16, 2008, 3:19pm UTC](https://forum.kirupa.com/t/using-a-web-service/263479 "2008-06-16T15:19:00Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![lec](https://avatars.discourse-cdn.com/v4/letter/l/a9adbd/32.png) [@lec](https://forum.kirupa.com/u/lec)
#### Post date: [June 16, 2008, 3:19pm UTC](https://forum.kirupa.com/t/using-a-web-service/263479/1 "2008-06-16T15:19:00Z")

</div>

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:

```auto
 
<?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.

---

<div class="post-metadata">

### Author: ![lec](https://avatars.discourse-cdn.com/v4/letter/l/a9adbd/32.png) [@lec](https://forum.kirupa.com/u/lec)
#### Post date: [June 16, 2008, 3:23pm UTC](https://forum.kirupa.com/t/using-a-web-service/263479/2 "2008-06-16T15:23:48Z")

</div>

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

_[MessagingError message=‘Destination ‘[https://secure.mojointeractive.com/Flex/Quote.cfc?wsdl](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.

---

<div class="post-metadata">

### Author: ![lec](https://avatars.discourse-cdn.com/v4/letter/l/a9adbd/32.png) [@lec](https://forum.kirupa.com/u/lec)
#### Post date: [June 16, 2008, 7:44pm UTC](https://forum.kirupa.com/t/using-a-web-service/263479/3 "2008-06-16T19:44:19Z")

</div>

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:

```auto
 
<?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.

```auto
 
<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.

---

<div class="post-metadata">

### Author: ![lec](https://avatars.discourse-cdn.com/v4/letter/l/a9adbd/32.png) [@lec](https://forum.kirupa.com/u/lec)
#### Post date: [June 16, 2008, 9:39pm UTC](https://forum.kirupa.com/t/using-a-web-service/263479/4 "2008-06-16T21:39:14Z")

</div>

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:

```auto
 
<?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>

```

---

<div class="post-metadata">

### Author: ![lec](https://avatars.discourse-cdn.com/v4/letter/l/a9adbd/32.png) [@lec](https://forum.kirupa.com/u/lec)
#### Post date: [June 16, 2008, 9:52pm UTC](https://forum.kirupa.com/t/using-a-web-service/263479/5 "2008-06-16T21:52:27Z")

</div>

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](http://www.macmartine.com/blog/2008/04/flex_and_coldfusion_remoteobje.html)

---

<div class="post-metadata">

### Author: ![lec](https://avatars.discourse-cdn.com/v4/letter/l/a9adbd/32.png) [@lec](https://forum.kirupa.com/u/lec)
#### Post date: [June 16, 2008, 9:54pm UTC](https://forum.kirupa.com/t/using-a-web-service/263479/6 "2008-06-16T21:54:35Z")

</div>

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