我從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
}
}
更多信息沒有看到實際調用該服務的代碼,這是很難知道發生了什麼事情。向我們展示UserService的代碼! – JeffryHouser 2012-03-28 20:20:42
我不確定我的理解。 .net代碼或由flex生成的代碼? – Radislav 2012-03-28 20:23:09
我已更新我的問題。 – Radislav 2012-03-28 20:26:04