Calling a method inside web service in action script 3.0

自闭症网瘾萝莉.ら 提交于 2019-12-04 16:06:47

问题


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


回答1:


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());
}



回答2:


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:

  • http://livedocs.adobe.com/flex/2/langref/flash/net/URLRequest.html
  • http://livedocs.adobe.com/flex/2/langref/flash/net/URLLoader.html



回答3:


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....



来源:https://stackoverflow.com/questions/730496/calling-a-method-inside-web-service-in-action-script-3-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!