2010-06-01 83 views
0

我是Flex新手,需要一些幫助來設置Web服務客戶端。Web服務動作錯誤

我有方法的Web服務:我在創建動作腳本調用這個服務面臨的問題

public String printEchoStr(String str); 

。我得到錯誤:

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

我不確定這是否是正確的方法。

謝謝,

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

生成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

您可以上傳生成的EchoService.as源代碼嗎? – Sophistifunk 2010-06-01 04:55:51

+0

我已經上傳了由Data-> Import WebService生成的EchoService的代碼 – 2010-06-01 12:52:58

+0

我試圖發送一個參數在TextArea中打印webservice的響應。 – 2010-06-01 13:19:56

回答

1
myService.printEchoStr(textAreaPrintEchoStr.text); 

printEchoStr方法EchoService類的期望一個PrintEcho對象,但您要通過textAreaPrintEchoStr.text,這是一個String