2012-07-24 57 views
0

我正在使用Flex SOAP Web服務,連接到我們的WSDL,並且所有內容都是花哨的。不過,我對網絡服務不熟悉,網絡人員正在度假,所以我有點困惑。我做的第一件事就是開始檢查連接:Flash AS3在for循環中調用WSDL

private function configXMLHandler(event:LoaderEvent):void { 
     fws.wsdl = checkWSDL; 
     fws.loadWSDL(); 
     fws.addEventListener(LoadEvent.LOAD, wsdlLoaded); 
    } 

    private function wsdlLoaded(event:LoadEvent):void { 
     checkAbstract = fws.getOperation("retrieveAssetIdbyLabel"); 
     checkAbstract.arguments = ["poll-asset-do-not-remove"]; 
     var token:AsyncToken = checkAbstract.send(); 
     token.addResponder(new Responder(checkAbstractResult, checkAbstractError)); 
    } 

    private function checkAbstractError(event:FaultEvent):void { 
     trace('Error in the WSDL'); 
    } 

    private function checkAbstractResult(event:ResultEvent):void { 

     if (event.result.returnCode == 0) { 
      trace('Web service check ok'); 

      initContentLoader(); 

     } else { 
      trace('Error in the WSDL'); 
      ) 

     } 

    } 

這工作得很好,我得到的結果,我想到的,所以我繼續前進。然後,我需要通過一個XML目錄遍歷並呼籲在XML每個資產相同的Web服務功能,我的想法是使用一個循環:

private function initContent(event:LoaderEvent):void { 
     assetList = event.target.content.asset; 

     for (var i:int = 0; i < assetList.length(); i++) { 
      assetAbstract = fws.getOperation("retrieveAssetIdbyLabel"); 
      assetAbstract.arguments = [assetList[i + assetCount].assetLabel]; //get the current index in the xmllist + the assetCount, grab the corresponding assetLabel from the XML and pass that to the web service 
      trace(assetAbstract.arguments); 
      var assetToken:AsyncToken = assetAbstract.send(); 
      assetToken.addResponder(new Responder(getAssetResult, getAssetError)); 
     } 
    } 

    private function getAssetResult(event:ResultEvent):void { 
     var treasuresAsset:TreasuresAsset = new TreasuresAsset(event.result.returnCode, assetList[assetCount].asset.assetLabel, assetList[assetCount].asset.assetImage, assetList[assetCount].asset.assetDescription); 
     addChild(treasuresAsset); 

     assetCount++; //increase the asset count 
    } 

    private function getAssetError(event:FaultEvent):void { 
     trace(event.fault); 
     trace('An error occured when we tried to get an asset id in the loop'); 
    } 

現在我得到一個錯誤:

Error opening URL 'http://www.nhm.ac.uk/web-services/VisitorService/' SOAPFault (Server): org.apache.axis2.databinding.ADBException: Unexpected subelement RetrieveAssetIdbyLabel

我的直接想法是,我需要爲xml中的每個資源創建一個Web服務的新實例,並重復我的第一個代碼。我可以只使用Web服務一次,是否需要重新創建整個過程?

謝謝。

回答

0

好的,所以我想通了,這是一個簡單的XML命名空間問題。

我代替:

assetAbstract.arguments = [assetList[i + assetCount].assetLabel]; 

有了:

var sender:String = assetList[i + assetCount].assetLabel; 
      assetAbstract.arguments = [sender]; 

和所有工作。