在动作脚本 3.0 中调用 Web 服务内部的方法

发布于 2024-07-17 04:48:09 字数 115 浏览 3 评论 0原文

我需要在 Web 服务中调用一个方法,并将操作脚本 3.0 中的参数传递给它 有人可以帮我吗? 我在互联网上搜索并找到了 Flex 的解决方案,但我不使用 Flex 我正在使用 Action script 3.0

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

清风夜微凉 2024-07-24 04:48:09

这是我在 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());
}

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());
}
月朦胧 2024-07-24 04:48:09

我使用这样的东西:

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

文档:

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:

聚集的泪 2024-07-24 04:48:09

您可以通过一种棘手的方法来使用Web服务,首先您通过在Flex环境中编译来制作swf,其中包括Web服务的导入语句,例如import mx.rpc.webservices。 现在编译它你将得到一个swf。 现在您转到as3.0并在舞台上制作一个空的影片剪辑并在链接属性中将其导入以进行运行时共享并将a.swf(ex)放在共享中的文本框中。现在您可以在动作脚本文件中导入该语句
导入mx.rpc.webservices.并使用与flex相同的方法。
你肯定能够访问网络服务......

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文