Search code examples
apache-flexairblazeds

Using Proxy Webservice with Adobe AIR/BlazeDS


I am trying to call a webservice using proxy. My settings for proxy-config on blazeds side are as below:

<destination id="ws-catalog">
    <properties>
        <wsdl>http://feeds.adobe.com/webservices/mxna2.cfc?wsdl</wsdl>
        <soap>*</soap>
    </properties>
    <adapter ref="soap-proxy"/>
</destination>

On Adobe AIR side, my code is:

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                       xmlns:s="library://ns.adobe.com/flex/spark" 
                       xmlns:mx="library://ns.adobe.com/flex/mx"
                       creationComplete="loadConfiguration()">
    <s:layout>
        <s:VerticalLayout/>
    </s:layout>

    <fx:Script>
        <![CDATA[
            import mx.messaging.ChannelSet;
            import mx.messaging.channels.AMFChannel;
            import mx.rpc.events.FaultEvent;
            import mx.rpc.events.ResultEvent;
            [Bindable]
            private var cs:ChannelSet;

            private function loadConfiguration():void
            {
                var amfChannel:AMFChannel = new AMFChannel("my-amf", 'http://localhost:8400/messagebroker/amf');
                cs = new ChannelSet();
                cs.addChannel(amfChannel);
            }

            protected function ws_resultHandler(event:ResultEvent):void
            {
                var obj:Object = event.result;
            }

            protected function ws_faultHandler(event:FaultEvent):void
            {
                var faultObj:Object = event.fault;
            }

            protected function button1_clickHandler(event:MouseEvent):void
            {
                ws.getOperation('getFeeds').send();
            }

        ]]>
    </fx:Script>

    <fx:Declarations>
        <s:WebService id="ws" 
                      channelSet="{cs}"
                      useProxy="true" 
                      destination="ws-catalog"
                      showBusyCursor="true"
                      result="ws_resultHandler(event)"
                      fault="ws_faultHandler(event)"
                      />
    </fx:Declarations>
    <s:Button label="CallWebService" click="button1_clickHandler(event)"/>
</s:WindowedApplication>

But now, whenever I launch my AIR app, am getting following error:

faultCode: InvokeFailed
faultDetail: Unable to load WSDL. If currently online, please verify the URI and/or format of the WSDL (null)
faultString: [MessagingError message='Destination 'ws-catalog' either does not exist or the destination has no channels defined (and the application does not define any default channels.)']

Can somebody help me OR point me to a similar solution? Thanks.


Solution

  • Please check the code below. It works on my machine. You need to wait a couple of seconds, getFeeds returns a lot of data.

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

    <fx:Script>
        <![CDATA[
            import mx.messaging.ChannelSet;
            import mx.messaging.channels.AMFChannel;
            import mx.rpc.events.FaultEvent;
            import mx.rpc.events.ResultEvent;
            import mx.rpc.soap.LoadEvent;
            import mx.rpc.soap.mxml.*;
            import mx.rpc.wsdl.WSDLOperation;
            [Bindable]
            private var cs:ChannelSet;
            [Bindable]
            var gateway:WebService
    
            private function loadConfiguration():void{
                var amfChannel:AMFChannel = new AMFChannel("my-amf", 'http://localhost:8400/samples/messagebroker/amf');
                cs = new ChannelSet();
                cs.addChannel(amfChannel);
                gateway = new WebService();
                gateway.channelSet = cs;
                gateway.destination = "ws-catalog";
                gateway.useProxy = true;
                gateway.addEventListener(ResultEvent.RESULT,ws_resultHandler);
                gateway.addEventListener(FaultEvent.FAULT,ws_faultHandler);
                gateway.loadWSDL();
            }
    
            protected function ws_resultHandler(event:ResultEvent):void{
                var obj:Object = event.result;
                trace("ok");
            }
    
            protected function ws_faultHandler(event:FaultEvent):void{
                var faultObj:Object = event.fault;
                trace("nok");
                trace(faultObj);
            }
    
            protected function button1_clickHandler(event:MouseEvent):void{
                gateway.getFeeds();
            }
    
    
        ]]>
    </fx:Script>
    
    <s:Button label="CallWebService" click="button1_clickHandler(event)"/>