Ben, below is a modified version of Jeff Tapper's AS class for webServices. Here's his original post: http://jeff.mxdj.com/as3_datamanager.htm. It solves the problem with the order of the arguments being sent randomly to the web service. Steven has me thinking more about the abstration of this solution. The CursorManager reference should probably be backed out to the command or whatever method you choose to call the service. Also. there's no reason to create a new Object() everytime. And....the WSDL should be stored on the server (FDS). But knowning that this will probably not be the final solution, I'm not putting much work into it yet. Hope this example helps.
Tim
package code.business {
import mx.managers.CursorManager;
import flash.events.EventDispatcher;
import mx.rpc.soap.WebService;
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
import mx.rpc.AbstractOperation;
import mx.controls.Alert;
import flash.util.*;
public class DataServices extends EventDispatcher {
private var ws:WebService;
private static var instanceMap:Object = new Object();
public function DataServices(pri:PrivateClass, wsdl:String)
{
this.ws = new WebService();
ws.wsdl = wsdl;
ws.loadWSDL();
ws.useProxy = false;
}
public static function getDataService(wsdl:String):DataServices
{
if(DataServices.instanceMap[wsdl] == null)
{
DataServices.instanceMap[wsdl] = new DataServices(new PrivateClass(),wsdl);
}
var ds:DataServices = DataServices.instanceMap[wsdl];
if(ds.ws.canLoadWSDL())
{
return ds;
} else {
throw new Error("BAD WSDL:"+wsdl);
}
}
public function makeRemoteCall(methodName:String,showBusyCursor:Boolean,args:Object):void
{
var op:mx.rpc.AbstractOperation = ws[methodName];
if(showBusyCursor)
{
CursorManager.setBusyCursor();
}
ws.addEventListener("result",onResult);
ws.addEventListener("fault",onFault);
if(args)
{
op.arguments = args;
}
op.send();
}
private function onResult(result:ResultEvent):void
{
CursorManager.removeBusyCursor();
this.dispatchEvent(result);
}
private function onFault(fault:FaultEvent):void
{
CursorManager.removeBusyCursor();
this.dispatchEvent(fault);
}
public override function toString():String
{
return "DataServices";
}
}
}
/** PrivateClass is used to make DataServices constructor private */
class PrivateClass
{
public function PrivateClass() {}
}
//----------------------------------
The authorsSearchOptionsVO is the same structure as the webService parameters.
To call the service class:
//----------------------------------
public function getAuthors( authorsSearchOptionsVO : authorsSearchOptionsVO ): void
{
var wsdl : String = ModelLocator.WSDL;
var showBusyCursor : Boolean = true
var args:Object = new Object();
args = authorsSearchOptionsVO;
dataServices = DataServices.getDataService(wsdl);
dataServices.addEventListener("result",onResult);
dataServices.addEventListener("fault",onFault);
dataServices.makeRemoteCall("getAuthors",showBusyCursor,args);
}
//----------------------------------
--- In [email protected], "ben.clinkinbeard" <[EMAIL PROTECTED]> wrote:
>
> Very cool. Thanks to both and Tim and Peter for your help.
>
> Not sure if I should start a new thread for this (if i should just let
> me know), but I am noticing some odd behavior when using
> mx.rpc.soap.WebService. When I try passing an arguments object in the
> send() method I am getting a fault with the following message: Array
> of input arguments did not contain a required parameter at position 1.
> When I assign the same object to the arguments property of my
> AbstractOperation, everything works fine. Here is my code:
>
> dmws = new WebService();
> dmws.loadWSDL([EMAIL PROTECTED]
> + "?WSDL");
> dmws.useProxy = false;
> dmws.addEventListener("result", onDmwsResult);
> dmws.addEventListener("fault", doFault);
>
> var op:AbstractOperation;
> op = dmws['GetDocument'];
>
> var args:Object = new Object();
>
> args.EnterpriseId = event.target.selectedItem.EnterpriseId;
> args.DocumentType = "EBD";
>
> args.ContainersToRetrieve = new Array();
> args.ContainersToRetrieve.push("Client");
> args.ContainersToRetrieve.push("IndustryTrends");
> args.ContainersToRetrieve.push("Fiduciary");
>
> args.MetadataToRetrieve = new Array("DocumentHistory");
>
>
> // this works
> op.arguments = args;
> op.send();
>
> // this does not work
> op.send(args);
>
> Thanks,
> Ben
>
> --- In [email protected], "ben.clinkinbeard"
> ben.clinkinbeard@ wrote:
> >
> > Why are these separate classes? More importantly, why does the mxml
> > version have capabilities that its super class does not? I like the
> > showBusyCursor functionality, but prefer to code in AS when possible.
> > Am I correct in assuming that these two things are mutually exclusive?
> >
> > Thanks,
> > Ben
> >
>
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
| Web site design development | Computer software development | Software design and development |
| Macromedia flex | Software development best practice |
YAHOO! GROUPS LINKS
- Visit your group "flexcoders" on the web.
- To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
- Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.

