在Adobe AIR / BlazeDS中使用代理Web服务

时间:2011-09-28 12:38:09

标签: flex air blazeds

我正在尝试使用代理调用Web服务。我在blazeds方面的proxy-config设置如下:

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

在Adobe AIR端,我的代码是:

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

但是现在,每当我启动我的AIR应用程序时,都会出现以下错误:

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.)']

有人可以帮助我或指出类似的解决方案吗? 感谢。

2 个答案:

答案 0 :(得分:0)

很难说不知道所有的配置。您可以查看以下几个原因:

-failure在services.xml中声明proxy-config.xml文件

-failure在项目中包含services.xml

- 无法为您的目的地声明频道

了解如何使用BlazeDS作为代理来调用Web服务的最佳方法是下载blazeds turnkey installation并查看示例。解压缩归档后,您可以在blazedsrootfolder / tomcat / webapps / samples中找到samples文件夹。您将找到一个显示您要执行的操作的示例。

答案 1 :(得分:0)

请检查以下代码。它适用于我的机器。您需要等待几秒钟,getFeeds会返回大量数据。

<?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)"/>