Forums: Flash:

 

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

first
 

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

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?

-------------------------------------------
blog ::: photos
quote
 

es!

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");

-------------------------------------------
blog ::: photos
quote
 

lithium

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!

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!

-------------------------------------------
blog ::: photos
quote
 

monoloco

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!

 
first
 

Forums: Flash: netconnection sending and receiving soap...as3 WITHOUT using Flex???

 
New Post
 
You must be logged in to post