2012-03-28 88 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