Today I struggled with the mx.rpc.soap.WebService class. What I wanted to do is call a .Net WebService method that has 3 arguments:
Authenticate(Username:String, Pwd:String, RememberMe:Boolean):String
This might look simple and it is, when you know which bugs to avoid.
I started out with this function:
public function AuthenticateUser(strUsername:String,strPwd:String,blRemember:Boolean):String {
var ws:WebService = new WebService();
var op:AbstractOperation;
ws.wsdl = wsdl;
ws.loadWSDL('yourwebserviceWSDL');
ws.useProxy = false;
op = ws['Authenticate'];
ws.addEventListener("result",doResults);
ws.addEventListener("fault",doFault);
op.send(strUsermame,strPwd,blRemember);
}
This should do the trick,... but it didn't. After tracing what happened in the webservice call I noticed that the argument values get mixed up with the argument names in the final SOAP call. Took me a good part of the day to figure this out....(this might be my own shortcomming :-))
Once I found the bug, a solution was easy to create, this is the final function:
public function AuthenticateUser(strUsername:String,strPwd:String,blRemember:Boolean):String {
var ws:WebService = new WebService();
var op:AbstractOperation;
var args:Object = new Object;
args.Username = strUsername;
args.Pwd = strPwd;
args.RememberMe = blRemember;
ws.wsdl = wsdl;
ws.loadWSDL('yourwebserviceWSDL');
ws.useProxy = false;
op = ws['Authenticate'];
ws.addEventListener("result",doResults);
ws.addEventListener("fault",doFault);
op.arguments = args;
op.send();
}
Lessons learned: do not trust the Webservice API to map your arguments into a SOAP call, do it yourself !
Having this, next up will be to create an authentication module that can be used in a web application... , going slow but steady.