2 Replies Latest reply on Mar 15, 2010 11:18 AM by TBag000

    WebService can load WSDL, but not call methods?

    TBag000

      I'm using mx.rpc.soap.WebService, to load a webservice and call methods on it.

      everything works fine for me when running locally,

      but when i host my swf on a website, i get a security error when i try to call the methods on the webservice.

      ive spent the last two days trying to figure out why this is happening, but the only ideas anyone has given me are all

      cross-domain related.  and while i agree that it appears to be the problem, i don't see any resolution.

      the service i am calling has allow-from * and i presume this should work.


      i have published this from Flash CS4, using the flex 3.3.04852 sdk swc's

      also tried flex sdk 3.5, and 4b2 just to see.  same results each time.

       

      if there is a better way to call a .net webservice i'd be thrilled to hear about it.

       

      here is my code:

       

      1. package
      2. {
      3.         import flash.display.Sprite;
      4.         import flash.events.Event;
      5.         import flash.text.TextField;
      6.         import flash.text.TextFieldAutoSize;
      7.         import mx.collections.ArrayCollection;
      8.         import mx.rpc.soap.*;
      9.         import mx.core.*;
      10.         import mx.rpc.events.*;
      11.       
      12.         import mx.utils.ObjectUtil;
      13.       
      14.         public class Main extends Sprite
      15.         {
      16.               
      17.                 private var ws:WebService = new WebService();
      18.                 private var tf:TextField = new TextField();
      19.               
      20.                 public function Main():void
      21.                 {
      22.                         if (stage) init();
      23.                         else addEventListener(Event.ADDED_TO_STAGE, init);
      24.                 }
      25.               
      26.                 private function init(e:Event = null):void
      27.                 {
      28.                         removeEventListener(Event.ADDED_TO_STAGE, init);
      29.                         // entry point
      30.                       
      31.                       
      32.                       
      33.                         /* http://feeds.adobe.com/crossdomain.xml
      34.                           *
      35.                           * <?xml version="1.0"?>
      36.                                  <cross-domain-policy>
      37.                                     <site-control  permitted-cross-domain-policies="by-content-type" />
      38.                                     <allow-access-from domain="*" />
      39.                                     <allow-http-request-headers-from domain="*" />
      40.                                  </cross-domain-policy>
      41.                           *
      42.                           */
      43.                         addChild(tf);
      44.                         tf.autoSize = TextFieldAutoSize.LEFT;
      45.                         tf.width = 600;
      46.                         tf.multiline = true;
      47.                       
      48.                         ws.addEventListener(LoadEvent.LOAD, onLoad);
      49.                         ws.addEventListener(InvokeEvent.INVOKE, onInvoke);
      50.                         ws.addEventListener(ResultEvent.RESULT, onResult);
      51.                         ws.addEventListener(FaultEvent.FAULT, onFault);
      52.                       
      53.                         // load wsdl succeeds in all cases
      54.                         ws.loadWSDL("http://feeds.adobe.com/webservices/mxna2.cfc?wsdl");
      55.                 }
      56.               
      57.                 private function onLoad(e:LoadEvent):void
      58.                 {
      59.                         tf.appendText("** " + e.toString() + "\n");
      60.                       
      61.                         // works when executed locally (during swf development)
      62.                         /*
      63.                                  ** [LoadEvent  location="http://feeds.adobe.com/webservices/mxna2.cfc?wsdl" type="load"  bubbles=false cancelable=true eventPhase=2]
      64.                                  ** [InvokeEvent  messageId="9F27FFAF-EFAC-1DA3-A7C7-50767D6E2899" type="invoke"  bubbles=false cancelable=false eventPhase=2]
      65.                                  ** [ResultEvent  messageId="FDFB38E1-8E49-6C40-2B16-50767E3B2959" type="result"  bubbles=false cancelable=true eventPhase=2]
      66.                                  Category 14 = Adobe AIR
      67.                                  Category 6 = Adobe Feeds
      68.                                  Category 10 = Acrobat
      69.                                  Category 1 = ColdFusion
      70.                                  Category 2 = Director
      71.                                  Category 3 = Dreamweaver
      72.                                  Category 4 = Flash
      73.                                  Category 8 = Fireworks
      74.                                  Category 15 = LiveCycle
      75.                                  Category 5 = Flex
      76.                                  Category 12 = Mobile and Devices
      77.                                  Category 9 = Photoshop
      78.                                  Category 7 = Technology
      79.                          */
      80.                               
      81.                       
      82.                       
      83.                         // webservice method call fails on cross-domain call (as  posted on webserver),
      84.                         /*
      85.                                  ** [LoadEvent  location="http://feeds.adobe.com/webservices/mxna2.cfc?wsdl" type="load"  bubbles=false cancelable=true eventPhase=2]
      86.                                  ** [InvokeEvent  messageId="C7760D07-6804-0807-9021-506C85C67983" type="invoke"  bubbles=false cancelable=false eventPhase=2]
      87.                                  ** [FaultEvent fault=[RPC Fault faultString="Security  error accessing url" faultCode="Channel.Security.Error"  faultDetail="Destination: DefaultHTTP"]  messageId="02281C42-BB8A-CB80-4E60-506C85D2847A" type="fault"  bubbles=false cancelable=true eventPhase=2]
      88.                          */
      89.                       
      90.                         ws.getCategories.send();
      91.                 }
      92.               
      93.                 private function onInvoke(e:InvokeEvent):void
      94.                 {
      95.                         tf.appendText("** "+e.toString()+"\n");
      96.                 }
      97.               
      98.                 private function onResult(e:ResultEvent):void
      99.                 {
      100.                         tf.appendText("** "+e.toString()+"\n");
      101.                         for each(var o:Object in e.result as ArrayCollection)
      102.                         {
      103.                                 tf.appendText("Category " + o.categoryId + " = " + o.categoryName+"\n");
      104.                         }
      105.                 }
      106.               
      107.                 private function onFault(e:FaultEvent):void
      108.                 {
      109.                         tf.appendText("** "+e.toString()+"\n");
      110.                 }
      111.               
      112.         }
      113.       
      114. }
        • 2. Re: WebService can load WSDL, but not call methods?
          TBag000 Level 1

          for the record, in case anyone else is suffering this same problem... here is my solution:

          in the cross-domain xml:

           

              <allow-http-request-headers-from domain="*" headers="*"/>

           

          i'm sure there is a specific setting that would be a better choice, but specifically i had to include the headers="x" attribute.

          the feeds.adobe.com/crossdomain.xml does NOT include this, and so my example code would never have worked in any case.

           

          i dont know if this is just the way that the WebService class works or what.  i was able to request the wsdl page just using a plain URLLoader.

          i cant see inside the classes to see what its doing internally.

           

          in any event, with this addition to my own crossdomain policy file, i am able to call my web service without error.