[英]Calling a method inside web service in action script 3.0
我需要在Web服務中調用一個方法,並將其從動作腳本3.0中傳遞給它的參數,有人可以幫助我嗎? 我在整個Internet上進行搜索,找到了Flex的解決方案,但我不使用Flex,我正在使用動作腳本3.0
我用這樣的東西:
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
文檔:
這是我在一個Flex項目中使用的代碼...
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();
}
然后這就是一旦加載WSDL會發生什么
protected function loadHandler(event:LoadEvent):void
{
// send() takes the service parameters
service.GetPayload.send("Product");
}
您只需要編寫兩個方法來處理服務返回的XML(數據以e4x格式返回:
protected function yourResultHandler(event:ResultEvent):void
{
_messageXml = XML(event.result);
}
proteted function yourFaultHandler(event:FaultEvent):void
{
Alert.show(event.toString());
}
您可以先通過一種棘手的方法使用Web服務,然后再在Flex環境中通過編譯生成swf,其中包括web服務的import語句,例如import mx.rpc.webservices。 現在編譯它,您將得到一個瑞士法郎。 現在您轉到as3.0,在舞台上制作一個空的movieclip,並在linkage屬性中將其導入以進行運行時共享,並將a.swf(ex)放在共享的文本框中。現在您可以在操作腳本文件import中導入該語句mx.rpc.webservices。並使用與flex相同的方法。 您一定可以訪問網絡服務。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.