2010-06-01 7 views
0

Je suis nouveau à Flex et j'avais besoin d'aide pour configurer le client de service Web.Erreur ActionScript du service Web

J'ai un service web de la méthode:

public String printEchoStr(String str); 

Je suis face à problème lors de la création de script d'action pour appeler ce service. Je reçois l'erreur:

1067: Implicit coercion of a value of type String to an unrelated type 
generated.webservices:PrintEcho. 

Je ne suis pas sûr si c'est la bonne manière.

Merci,

-H

<?xml version="1.0" encoding="utf-8"?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" 
    xmlns:srv="generated.webservices.*" 
    creationComplete="initFunc()"> 
    <mx:Script> 
     <![CDATA[ 
      import generated.webservices.EchoService; 
      import generated.webservices.PrintEchoStrResultEvent; 
      import generated.webservices.PrintEchoResultEvent; 
      import mx.rpc.events.ResultEvent; 
      import mx.rpc.events.FaultEvent; 
      import mx.controls.Alert; 
      import generated.webservices.PrintEchoStr; 
      import generated.webservices.PrintEcho; 

      public var myService:EchoService = new EchoService(); 

      private function initFunc():void{ 
       myService.addprintEchoStrEventListener(argPrintEchoStr); 
/*-------------- 
1067: Implicit coercion of a value of type String to an unrelated type 
generated.webservices:PrintEcho. at line below 
----------------*/ 
       myService.printEchoStr(textAreaPrintEchoStr.text); 
       myService.addEventListener(FaultEvent.FAULT,myServices_faultHandler); 
      } 

      public function argPrintEchoStr(event:PrintEchoStrResultEvent):void{ 
       trace(event.result); 
      } 

      private function myServices_faultHandler(event:FaultEvent):void { 
       Alert.show(event.fault.faultString,"error with WebServices"); 
      } 

     ]]> 
    </mx:Script> 
    <mx:TextArea id ="textAreaPrintEchoStr" 
     x="81" y="125"/> 

</mx:Application> 

source généré de EchoService.as EchoService.as

package generated.webservices 
{ 
    import mx.rpc.AsyncToken; 
    import flash.events.EventDispatcher; 
    import mx.rpc.events.ResultEvent; 
    import mx.rpc.events.FaultEvent; 
    import flash.utils.ByteArray; 
    import mx.rpc.soap.types.*; 

    /** 
    * Dispatches when a call to the operation printEcho completes with success 
    * and returns some data 
    * @eventType PrintEchoResultEvent 
    */ 
    [Event(name="PrintEcho_result", type="generated.webservices.PrintEchoResultEvent")] 

    /** 
    * Dispatches when a call to the operation printEchoStr completes with success 
    * and returns some data 
    * @eventType PrintEchoStrResultEvent 
    */ 
    [Event(name="PrintEchoStr_result", type="generated.webservices.PrintEchoStrResultEvent")] 

    /** 
    * Dispatches when the operation that has been called fails. The fault event is common for all operations 
    * of the WSDL 
    * @eventType mx.rpc.events.FaultEvent 
    */ 
    [Event(name="fault", type="mx.rpc.events.FaultEvent")] 

    public class EchoService extends EventDispatcher implements IEchoService 
    { 
     private var _baseService:BaseEchoService; 

     /** 
     * Constructor for the facade; sets the destination and create a baseService instance 
     * @param The LCDS destination (if any) associated with the imported WSDL 
     */ 
     public function EchoService(destination:String=null,rootURL:String=null) 
     { 
      _baseService = new BaseEchoService(destination,rootURL); 
     } 

     //stub functions for the printEcho operation 


     /** 
     * @see IEchoService#printEcho() 
     */ 
     public function printEcho(printEcho:PrintEcho):AsyncToken 
     { 
      var _internal_token:AsyncToken = _baseService.printEcho(printEcho); 
      _internal_token.addEventListener("result",_printEcho_populate_results); 
      _internal_token.addEventListener("fault",throwFault); 
      return _internal_token; 
     } 
     /** 
     * @see IEchoService#printEcho_send() 
     */  
     public function printEcho_send():AsyncToken 
     { 
      return printEcho(_printEcho_request.printEcho); 
     } 

     /** 
     * Internal representation of the request wrapper for the operation 
     * @private 
     */ 
     private var _printEcho_request:PrintEcho_request; 
     /** 
     * @see IEchoService#printEcho_request_var 
     */ 
     [Bindable] 
     public function get printEcho_request_var():PrintEcho_request 
     { 
      return _printEcho_request; 
     } 

     /** 
     * @private 
     */ 
     public function set printEcho_request_var(request:PrintEcho_request):void 
     { 
      _printEcho_request = request; 
     } 

      /** 
     * Internal variable to store the operation's lastResult 
     * @private 
     */ 
     private var _printEcho_lastResult:PrintEchoResponse; 
     [Bindable] 
     /** 
     * @see IEchoService#printEcho_lastResult 
     */ 
     public function get printEcho_lastResult():PrintEchoResponse 
     { 
      return _printEcho_lastResult; 
     } 
     /** 
     * @private 
     */ 
     public function set printEcho_lastResult(lastResult:PrintEchoResponse):void 
     { 
      _printEcho_lastResult = lastResult; 
     } 

     /** 
     * @see IEchoService#addprintEcho() 
     */ 
     public function addprintEchoEventListener(listener:Function):void 
     { 
      addEventListener(PrintEchoResultEvent.PrintEcho_RESULT,listener); 
     } 

     /** 
     * @private 
     */ 
     private function _printEcho_populate_results(event:ResultEvent):void 
     { 
      var e:PrintEchoResultEvent = new PrintEchoResultEvent(); 
        e.result = event.result as PrintEchoResponse; 
           e.headers = event.headers; 
        printEcho_lastResult = e.result; 
        dispatchEvent(e); 
        } 

     //stub functions for the printEchoStr operation 


     /** 
     * @see IEchoService#printEchoStr() 
     */ 
     public function printEchoStr(printEchoStr:PrintEchoStr):AsyncToken 
     { 
      var _internal_token:AsyncToken = _baseService.printEchoStr(printEchoStr); 
      _internal_token.addEventListener("result",_printEchoStr_populate_results); 
      _internal_token.addEventListener("fault",throwFault); 
      return _internal_token; 
     } 
     /** 
     * @see IEchoService#printEchoStr_send() 
     */  
     public function printEchoStr_send():AsyncToken 
     { 
      return printEchoStr(_printEchoStr_request.printEchoStr); 
     } 

     /** 
     * Internal representation of the request wrapper for the operation 
     * @private 
     */ 
     private var _printEchoStr_request:PrintEchoStr_request; 
     /** 
     * @see IEchoService#printEchoStr_request_var 
     */ 
     [Bindable] 
     public function get printEchoStr_request_var():PrintEchoStr_request 
     { 
      return _printEchoStr_request; 
     } 

     /** 
     * @private 
     */ 
     public function set printEchoStr_request_var(request:PrintEchoStr_request):void 
     { 
      _printEchoStr_request = request; 
     } 

      /** 
     * Internal variable to store the operation's lastResult 
     * @private 
     */ 
     private var _printEchoStr_lastResult:PrintEchoStrResponse; 
     [Bindable] 
     /** 
     * @see IEchoService#printEchoStr_lastResult 
     */ 
     public function get printEchoStr_lastResult():PrintEchoStrResponse 
     { 
      return _printEchoStr_lastResult; 
     } 
     /** 
     * @private 
     */ 
     public function set printEchoStr_lastResult(lastResult:PrintEchoStrResponse):void 
     { 
      _printEchoStr_lastResult = lastResult; 
     } 

     /** 
     * @see IEchoService#addprintEchoStr() 
     */ 
     public function addprintEchoStrEventListener(listener:Function):void 
     { 
      addEventListener(PrintEchoStrResultEvent.PrintEchoStr_RESULT,listener); 
     } 

     /** 
     * @private 
     */ 
     private function _printEchoStr_populate_results(event:ResultEvent):void 
     { 
      var e:PrintEchoStrResultEvent = new PrintEchoStrResultEvent(); 
        e.result = event.result as PrintEchoStrResponse; 
           e.headers = event.headers; 
        printEchoStr_lastResult = e.result; 
        dispatchEvent(e); 
        } 

     //service-wide functions 
     /** 
     * @see IEchoService#getWebService() 
     */ 
     public function getWebService():BaseEchoService 
     { 
      return _baseService; 
     } 

     /** 
     * Set the event listener for the fault event which can be triggered by each of the operations defined by the facade 
     */ 
     public function addEchoServiceFaultEventListener(listener:Function):void 
     { 
      addEventListener("fault",listener); 
     } 

     /** 
     * Internal function to re-dispatch the fault event passed on by the base service implementation 
     * @private 
     */ 

     private function throwFault(event:FaultEvent):void 
     { 
      dispatchEvent(event); 
     } 
    } 
} 
+0

Pouvez-vous télécharger la source générée pour EchoService.as? – Sophistifunk

+0

J'ai téléchargé le code de EchoService généré par Data-> Import WebService –

+0

J'essaie d'envoyer un paramètre imprimer la réponse du webservice dans le TextArea. –

Répondre

1
myService.printEchoStr(textAreaPrintEchoStr.text); 

méthode printEchoStr de EchoService classe attend un PrintEcho objet, mais vous passez textAreaPrintEchoStr.text, qui est un String