【问题标题】:SOAP web services from AS3, without Flex?来自 AS3 的 SOAP Web 服务,没有 Flex?
【发布时间】:2009-11-10 17:46:19
【问题描述】:

在不使用 Flex 框架的情况下,从 ActionScript 3 调用 SOAP Web 服务的最佳库/包/类是什么?

【问题讨论】:

    标签: actionscript-3 actionscript soap


    【解决方案1】:

    推荐阅读: 具有设计模式的高级 ActionScript 3 通过乔伊洛特和丹尼帕特森 转到第 15 章以获得更好、更完整的解决方案。

    我的示例代码:

    private var xmlResults:XML = new URLLoader;
    private var urlLoader:URLLoader = new URLLoader();
    
    
    public function fErrorHandler(e:IOErrorEvent):void {
       trace("xml failed!");
            }
    
    
    //when the "loader" event object finishes the loading of the xml file, run other needed functions to process the data 
    private function fLoaderCompleteHandler(event:Event):void {
    
       trace("xml loaded!!"); //jwt testing
       var result2:XML = new XML(urlLoader.data); // loads the xml file data into the xml object
       xmlResults = result2; //have the global xml object equal the current data loaded xml object 
       result2 = null; // dont need current xml object any more so erase it
    
       fParseXML(0); //process the first set of records from the xml object
       trace("found xml" + xmlResults.toString()); 
            } 
    
    
    public function fParseXML(intAddNum:Number):void{
       //create variables to store the record info
       //
       var envelope:XML = xmlResults; //XML(urlLoader.data);
       var soap:Namespace = envelope.namespace("soap");
       var responseN:Namespace = new Namespace("http://www.domain.com/school/ServiceCollege");
       var resultL:XMLList = envelope.soap::Body.responseN::HelloTestResponse.responseN::HelloTestResult;
    
       var strTest:String;
       //if only one response field will be return by the web service
       strTest = resultL; 
       //do something like this if multiple  response feilds will be returned
       //strTest = resultL.response::schoolName.toString(); 
       trace("parsing:" + strTest);
       trace("done loading:");
      }
    
    
     public function fBeginRequest():void{
      var strXMLDataRequest:String
      var urlRequest:URLRequest = new URLRequest();
      urlRequest.contentType = "text/xml; charset=utf-8";
      urlRequest.method = "POST";
      urlRequest.url = "http://www.domain.com/school/serviceCollege.asmx";  
      var soapAction:URLRequestHeader = new URLRequestHeader("SOAPAction","http://www.domain.com/school/ServiceCollege/HelloTest");
      urlRequest.requestHeaders.push(soapAction);
      strXMLDataRequest = "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">";
       strXMLDataRequest = strXMLDataRequest + "<soap:Body>";
       strXMLDataRequest = strXMLDataRequest + "<HelloTest xmlns=\"http://www.domain.com/school/ServiceCollege\" />";
       strXMLDataRequest = strXMLDataRequest + "</soap:Body>";
       strXMLDataRequest = strXMLDataRequest + "</soap:Envelope>";
        urlRequest.data =  new XML(strXMLDataRequest);
         urlLoader.load(urlRequest);
          urlLoader.addEventListener(IOErrorEvent.IO_ERROR, fErrorHandler); //add the event to the "loader" object
          urlLoader.addEventListener(Event.COMPLETE, fLoaderCompleteHandler); //add the event to the "loader" object
     }
    

    肥皂请求:

    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <soap:Body>
        <HelloTest xmlns="http://www.domain.com/school/ServiceCollege" />
      </soap:Body>
    </soap:Envelope>
    

    肥皂反应:

    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <soap:Body>
        <HelloTestResponse xmlns="http://www.domain.com/school/ServiceCollege">
          <HelloTestResult>string</HelloTestResult>
        </HelloTestResponse>
      </soap:Body>
    </soap:Envelope>
    

    【讨论】:

      【解决方案2】:

      我发现this post 非常有用。 总的来说,这是一个很好的提示:添加一个 swc 以在 Flash 中启用 Flex 类。

      【讨论】:

        【解决方案3】:

        您是否有不想使用 flex 库的原因?据我了解,仅在应用程序中使用您需要的组件不会给您带来任何性能问题。

        不过看看:http://alducente.wordpress.com/2007/10/27/web-service-in-as3-release-10/

        我不确定它是否是最好的,但我的一位同事向 e 推荐了它。

        【讨论】:

        猜你喜欢
        • 2011-07-21
        • 1970-01-01
        • 1970-01-01
        • 2012-07-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多