2012-03-28 112 views
0

我從flex調用web服務時遇到了一些問題。我有名稱UserService服務與一個方法字符串GetData(int i)。我想從flex調用這個方法並獲取數據。我的代碼是在這裏:如何從flex調用web服務

    protected function application1_creationCompleteHandler(event:FlexEvent):void 
     { 
      uService = new UserService(); 
      uService.addEventListener("hello", echoResultHandler); 
      uService.GetData(1);        
     } 

     public function echoResultHandler(event:ResultEvent):void { 
      var retStr:String = event.result as String;     
      var retInt:int = event.result.echoInt; 
      Alert.show('want to play', retStr); 
     } 

可能是我的問題並不困難,但我不明白爲什麼它不起作用..任何人都可以幫助我嗎?

服務代碼,當我向servese添加引用時由flex生成。

internal class _Super_UserService extends com.adobe.fiber.services.wrapper.WebServiceWrapper 
{ 


    public function _Super_UserService() 
    { 

     _serviceControl = new mx.rpc.soap.mxml.WebService(); 
     var operations:Object = new Object(); 
     var operation:mx.rpc.soap.mxml.Operation; 

     operation = new mx.rpc.soap.mxml.Operation(null, "GetData"); 
     operation.resultType = String; 
     operations["GetData"] = operation; 

     _serviceControl.operations = operations; 
     try 
     { 
      _serviceControl.convertResultHandler = com.adobe.serializers.utility.TypeUtility.convertResultHandler; 
     } 
     catch (e: Error) 
     { } 


     preInitializeService(); 
     model_internal::initialize(); 
    } 

    protected function preInitializeService():void 
    { 


     _serviceControl.service = "UserService"; 
     _serviceControl.port = "BasicHttpBinding_IUserService"; 
     wsdl = "http://localhost:3905/UserService.svc?wsdl"; 
     model_internal::loadWSDLIfNecessary(); 
    } 

    public function GetData(value:int) : mx.rpc.AsyncToken 
    { 
     model_internal::loadWSDLIfNecessary(); 
     var _internal_operation:mx.rpc.AbstractOperation = _serviceControl.getOperation("GetData"); 
     var _internal_token:mx.rpc.AsyncToken = _internal_operation.send(value) ; 
     return _internal_token; 
    } 

} 

繼承類:

public class UserService extends _Super_UserService 
{ 

    protected override function preInitializeService():void 
    { 
     super.preInitializeService(); 
     // Initialization customization goes here 
    } 

} 
+0

var call : Asynctoken = uService.GetData(1); call.addResponder(new AsyncResponder(echoResultHandler)); 

更多信息沒有看到實際調用該服務的代碼,這是很難知道發生了什麼事情。向我們展示UserService的代碼! – JeffryHouser 2012-03-28 20:20:42

+0

我不確定我的理解。 .net代碼或由flex生成的代碼? – Radislav 2012-03-28 20:23:09

+0

我已更新我的問題。 – Radislav 2012-03-28 20:26:04

回答

4

你UserService類從不調度名爲 「你好」 的活動;所以你的結果處理程序永遠不會被解僱。我認爲你需要添加一個結果處理程序到ASynctoken。在AsyncResponderAsyncToken

+0

謝謝,我會在稍後檢查。希望能幫助到你。 – Radislav 2012-03-29 11:51:04

+0

我完成了你所說的所有事情,但它不能以任何方式工作。 echoResultHandler沒有被調用...我不明白爲什麼:( – Radislav 2012-03-29 18:57:37

+0

謝謝,我發現我的問題的原因http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/rpc/ AsyncResponder.html#AsyncResponder%28 – Radislav 2012-03-29 19:00:55