views:

3515

answers:

6

I need to call a method inside web service and passing to it it's parameters from action script 3.0 can anyone help me plz? i searched all over the internet and found solutions with flex and i am not working with flex i am working with action script 3.0

A: 

I use something like this:

var request:URLRequest = new URLRequest();
request.url = 'http://example.org';

// If you're POSTing data:
request.method = URLRequestMethod.POST;
request.data = new URLVariables({ /* Your object */ });

var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES; // If you're using POST
try{
    loader.load(request);
}catch(error:Error){
    // Handle error
}

trace(loader.data); // Result

Documentation:

Ron DeVera
Mr.Ron i mentioned in my question that i need to call a method inside a web service not to request file or page. The code that u wrote is suitable for requesting Asp page but in the web service the issue differ and we need to use SOAP and encapsulate data inside itRead the questionfirst before ans
Ahmy
Ahmy, I read your question, but you didn't specify a SOAP-based web service. There are multiple types of web services; my answer is catered toward RESTful services because have been popular recently.
Ron DeVera
If it's a .Net service, you can easily enable POST and GET calls beside the default SOAP. It's built in, just a setting that needs to flipped.
Lillemanden
A: 

Here is the code that I used in one of my Flex projects...

import mx.rpc.soap.WebService;

public var service:WebService = new WebService();

override protected function initializationComplete():void
{
    service.wsdl = "http://localhost:1133/YourService.asmx?wsdl"

    // GetPayload is the method name you're calling on your web service
    service.GetPayload.resultFormat = "e4x";
    service.GetPayload.addEventListener("result", yourResultHandler);
    service.GetPayload.addEventListener("fault", yourFaultHandler);

    // Method to call once the WSDL is loaded
    service.addventListener(LoadEvent.LOAD, loadHandler);

    service.loadWSDL();
}

Then here is what happens once the WSDL is loaded

protected function loadHandler(event:LoadEvent):void
{
    // send() takes the service parameters
    service.GetPayload.send("Product");
}

You just need to write the two methods to handle the XML returned by your services (the data is returned in e4x format:

protected function yourResultHandler(event:ResultEvent):void
{
    _messageXml = XML(event.result);
}

proteted function yourFaultHandler(event:FaultEvent):void
{
    Alert.show(event.toString());
}
Justin Niessner
I am not using Flex, i mentioned in my question that i need solution for calling method inside web servie in Action Script 3.0
Ahmy
You don't need to be using Flex to use the mx.rpc.soap.WebServices namespace.
Justin Niessner
when i import it in Action Script 3.0 it reports to me:1172: Definition mx.rpc.soap:WebService could not be found.???????????????????????????
Ahmy
Hmmm...is it possible for you to just download the Flex SDK from http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+3You can then include the src folder from the SDK to your Flash Classpath.
Justin Niessner
A: 

i have used above tchnique but i facing errors in these lines // ImthePm is a webservice public var service:imthePM= new imthePM();

  1. service.GetAllProjects.resultFormat = "e4x"; 2.service.GetAllProjects.addEventListener("result", yourResultHandler);
  2. service.addventListener(LoadEvent.LOAD, loadHandler);
  3. service.GetAllProjects.send();

Error: Call to possibly undifined property GetAllProjects through a reference with a static type ImthePm .

Can you help me to solve this problem

A: 

What format is the web service? Text, XML?

JasonMichael
A: 

hi. you can use the web services by one of the tricky method first you make swf by compiled in flex environment which includes the import statements of webservice like import mx.rpc.webservices. now compile it you will get a swf. now you go to as3.0 and make a empty movieclip on stage and in linkage property put it import for runtime sharing and put the a.swf(ex)on textbox in sharing.now you can import the statement in your action script file import mx.rpc.webservices.and use the method same as flex. definately u will be able to access web services....

govind maheshwari
A: 

Simply the best script about WebService! Well Done!

Fabio