TwelvestoneFlash

netconnection sending and receiving soap...as3 WITHOUT using Flex???


Sign in

  • Waiting for Godot ( 730 k posts )
    Just conversation.
  • Thunder Dome ( 23 k posts )
    Photoshop Tennis and Collabs.
  • Photography ( 5.1 k posts )
    For all you shutterbugs, sh...
  • Flash ( 18 k posts )
    ActionScripting to tweens, ...
  • Front End ( 5.9 k posts )
    general front end design an...
  • Back End ( 9.7 k posts )
    serverside scripting, progr...
  • Projects and Theory ( 12 k posts )
    This forum is for discussio...
  • FAQ ( 269 posts )
    All those nagging questions...
  • Design ( 17 k posts )
    graphics & all aspects of g...
  • Purgatory ( 3.6 k posts )
    12stone Jail, feel free to ...
es!
 
2007-05-31

So I am working on this project where I need to consume a .NET web service. In Flash 8 it was cool because I could use the (built in) web services class. But for this project I am using Flash 9 / as3, and so there are no built-in classes for handling web services.

I am not using Flex for this project. Flex is not an option.

Also, I am kind of new to the whole Web Services thing. If I am overlooking something easy, please let me know.

kthxbi

-eS?

es!
 
2007-05-31

never mind...sorted it out...

Here is a code snippet:

package { import flash.net.*; import flash.xml.XMLDocument; import flash.events.Event; import flash.events.ErrorEvent; public class MyWebService { public var feedURL:String; public var returnXML:XML;

    public var isLoaded:Boolean = false;
    private var urlLoader:URLLoader;
    public var soapXML:XML;
    public var dataXML:XML;
    public var soap12:Namespace = new Namespace("http://www.w3.org/2003/05/soap-envelope");
    public var xsi:Namespace = new Namespace("http://www.w3.org/2001/XMLSchema-instance");
    public var xsd:Namespace = new Namespace("http://www.w3.org/2001/XMLSchema");

    public function MyWebService() {}

    public function loadService($feedURL:String):void {
        isLoaded = false;
        feedURL = $feedURL;

        var urlRequest:URLRequest = new URLRequest(feedURL);
        urlRequest.method=URLRequestMethod.POST;
        urlRequest.requestHeaders.push(new URLRequestHeader("Content-Type", "application/soap+xml"));

        urlRequest.data = null /*  put SOAP request XML here  */;
        urlLoader = new URLLoader();
        urlLoader.dataFormat = URLLoaderDataFormat.TEXT;
        urlLoader.addEventListener("complete", onLoaded);
        urlLoader.addEventListener("ioerror", ifFailed);
        urlLoader.load(urlRequest);
    }
    public function onLoaded():void {trace("IT WORKEDED")}
    public function ifFailed():void {trace("IT FAILEDED");}
}

}

call it as follows:

var fnord.MyWebService = new MyWebService(); fnord.loadService("http://www.myWebServiceURL.cx");

lithium
 
2007-06-01

if you're consuming soap web services, you might want to set your urlLoader.dataFormat to "e4x" so you can use the nifty new xml parsing to process the results.

es!
 
2007-06-01

I didn't have any difficulty parsing it as is (I don't think...) but I will do as you say. Thanks for the tip!

monoloco
 
2007-07-25

I'm really new to Web Services and am trying to get them to work in AS3.0. I might be missing something here, but looking at the code snippet, I'm still confused as to how the Namespace objects get included into the SOAP request. Also, where does the method name of the method being called get included?

Maybe all this stuff happens when you replace null with your SOAP in the below line from your example

        urlRequest.data = null /*  put SOAP request XML here  */;

Any help welcomed!

Storm
 
2009-04-09

Resurrecting this thread......because it's sort of related.

I have a project requiring .NET WebServices and I built it first in AS 2 and now moving to AS3. First of all, this was a pain with the loss of the WebService class in AS3. I used alducente's AS3 WebServices classes and they work with some tweaking.

Here's where I need help on because I'm not a good "programmery thinker"......

The project is a Flash-based server 'translator' for lack of a better term. Honda has internal and external resources building technical training (I used to build these when I first came here) and they all tie in to a .NET services wrapper to store test scores, module completion dates, log ins, or key value pairs for anything really.

In order to streamline the process, I had our .NET guys use SOAP and minimize the function calls. I give the Flash Training teams a small component that loads my .swf from the server and open up functions for them to send only the necessary data to MY SWF which calls the .NET functions passing along all the real secure log-in specific data.

Eg. Vendor builds training that must set a test score. I give them a component to insert and name WebServices. They call WebServices.setTestScore("90"); My WebServices component pulls in the server-based .swf with all the functions such as setTestScore. It takes the setTestScore function call with "90" adds in all the necessary information (name, id, session, whateverelse from the entire internal system that the .NET guys need) then call the .NET WebServices. I receive the SOAP object and pass that back to the root level call for the vendor to receive and ok message or whatever they need as response to that function.

This works perfectly in AS2 because my loadMovie pulls in my server-based swf exposing all the functions written in it as it replaces the component used to call it.

loadMovie("ServerBased.swf.swf", this);

In AS3, I'm not sure what I actually need to call to replace the MovieClip component that calls it. Right now it is:

var request:URLRequest = new URLRequest("ServerBased.swf"); var loader:Loader = new Loader(); loader.load(request); addChild(loader);

IF they call WebServices.setTestScore, it doesn't work obviously. But would the code be WebServices.loader.setTestScore (ok, that doesn't work!!).

What is a better process to have my little component call in serverbased functions to expose them without giving them the full path to load this .swf in AS3. I'm confused.

Storm
 
2009-04-09

answer (tentatively):

serverbased.swf must include: Security.allowDomain( this.root.loaderInfo.loaderURL ); to allow the parent calling it to access its functions.

parent MC can use: var connector:MovieClip = new MovieClip(); connector = MovieClip(loader.content);

whereby the main vendor module can use WebServices.connector.setTestScore("90");

Is there a way I can have the loaded swf still replace the one who calls it thereby reducing it to Webservices.functionToCall();?

Storm
 
2009-04-10

What would be my best practice for AS3 to have a component 'suck in' AS3 code from a server so that it's always up to date?

As mentioned, in AS2 it works fine.

But in AS3, I'm trying to figure out what is the best plan of attack. Can anyone help?

Sorry, you must be a member to post to a conversation. Either log in or sign up to get involved.
TwelvestoneFlash

netconnection sending and receiving soap...as3 WITHOUT using Flex???