Flex 中动态调用 WebService
Flex 中动态调用 WebService
2008-07-24 12:56
import mx.rpc.events.*;
import mx.rpc.AbstractOperation;
import mx.rpc.soap.WebService;
import mx.rpc.*;
import mx.controls.*;
private function UserLogin(user:String,pass:String):void{
var ws:WebService = new WebService();
var op:AbstractOperation;
var loginUser:Object = new Object;
var args:Object = new Object; //参数
loginUser.Name = user;
loginUser.Pwd = pass;
args.loginUser =loginUser;
ws.loadWSDL('http://localhost/service.asmx?WSDL');
ws.useProxy = false;
op = ws['Login']; //调用的函数名
ws.addEventListener("result",WsResult);
ws.addEventListener("fault",WsFault);
op.arguments = args;
op.send();
}
private var oper:OperatorInfo = new OperatorInfo(); //返回值
private function WsFault(event:FaultEvent):void{
Alert.show(event.toString(),'error');
}
private function WsResult(event:ResultEvent):void{
if(event.result != null){
oper.Name = event.result.Name;
oper.ID = event.result.ID;
oper.Password = event.result.Password;
oper.RoleID = event.result.RoleID;
oper.UserGroupID = event.result.UserGroupID;
asdf.text=oper.Name;
}
else{
asdf.text="login error";
}
}
import mx.rpc.AbstractOperation;
import mx.rpc.soap.WebService;
import mx.rpc.*;
import mx.controls.*;
private function UserLogin(user:String,pass:String):void{
var ws:WebService = new WebService();
var op:AbstractOperation;
var loginUser:Object = new Object;
var args:Object = new Object; //参数
loginUser.Name = user;
loginUser.Pwd = pass;
args.loginUser =loginUser;
ws.loadWSDL('http://localhost/service.asmx?WSDL');
ws.useProxy = false;
op = ws['Login']; //调用的函数名
ws.addEventListener("result",WsResult);
ws.addEventListener("fault",WsFault);
op.arguments = args;
op.send();
}
private var oper:OperatorInfo = new OperatorInfo(); //返回值
private function WsFault(event:FaultEvent):void{
Alert.show(event.toString(),'error');
}
private function WsResult(event:ResultEvent):void{
if(event.result != null){
oper.Name = event.result.Name;
oper.ID = event.result.ID;
oper.Password = event.result.Password;
oper.RoleID = event.result.RoleID;
oper.UserGroupID = event.result.UserGroupID;
asdf.text=oper.Name;
}
else{
asdf.text="login error";
}
}