加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

FMS 调用 WEBSERVICE(1)

发布时间:2020-12-16 23:47:22 所属栏目:安全 来源:网络整理
导读:Here's a very simple example on how to invoke and consume a WSDL webservice using serverside Actionscript. You will need?Flash Media Server 2?for this,it will not work in Flash Communication Server. The Webservice I am consuming in this ex

Here's a very simple example on how to invoke and consume a WSDL webservice using serverside Actionscript. You will need?Flash Media Server 2?for this,it will not work in Flash Communication Server.

The Webservice I am consuming in this example simply returns the currency exchange rate between two countries. For each country we must pass a string identifying the country,in this case I use 'UK' and 'USA'.

What follows is pure ASC (serverside Actionscript). No .fla file or clientside code is needed to run this.

Here is the content of my main.asc file (you can just copy and paste this code and save it as 'main.asc'):

// load necessary files (the docs don't tell you this...)
load( "webservices/WebServices.asc");

application.onAppStart = function() {
???// set up our webservice URL. This service returns an exchange rate between 2 countries????
var wsdlURI =? "http://www.xmethods.net/sd/2001/CurrencyExchangeService.wsdl";
???
???// create the service????rateService = new WebService(wsdlURI);
???
???// Handle the WSDL loading event.????rateService.onLoad = function(wsdl){
??????trace( "--- onLoad");
??????trace(wsdl);
??????trace( "--- end onLoad");
???}
???
???// If the WSDL fails to load the onFault event is fired.????rateService.onFault = function(fault){
??????trace( "--- rateService onFault");
??????trace( fault.faultstring );
??????trace( "--- end rateService onFault");
???}
???
???// This invokes the remote method 'getRate' an asynchronous callback.? ???// We use 'UK' and 'USA' as the 2 countries to query.????callback = rateService.getRate( "UK",? "USA");
???
???// Handle a successful result. This is the important bit :-)????callback.onResult = function(result) {
??????trace( "--- Result");
??????trace(? "Result. The Exchange Rate is: "?+ result);
??????trace(? "1 Pound Sterling will today buy you "?+ result +? " US Dollar.");
??????trace( "--- end Result");
???}
???// Handle an error result.????callback.onFault = function(fault){
??????trace( "--- callback onFault");
??????trace( fault.faultstring );
??????trace( "--- end callback onFault");
???}
}

In order to run this code you need to create a new application inside your FMS2's applications directory. I called my folder 'wsdl'. Next you should open the Flash Media Server admin console and load the 'wsdl' application. Then hit reload application. You should see the following traces:

Unloaded application instance wsdl/_definst_
WebServices Loaded successfully.
12/16 10:12:34 [INFO] : Queing call getRate
12/16 10:12:35 [INFO] : Made SOAPCall for operation getRate
--- onLoad
String too long to display
--- end onLoad
12/16 10:12:35 [INFO] : Invoking previously queued call getRate
12/16 10:12:35 [INFO] SOAP: Asynchronously invoking SOAPCall: getRate(UK,USA)
param:country1 UK
param:country2 USA
param:Result undefined
--- Result
Result. The Exchange Rate is: 1.7724
1 Pound Sterling will today buy you 1.7724 US Dollar.
--- end Result

Note that the traces such as

param:country1 UK
param:country2 USA
param:Result undefined
are generated by the 'imported' Actionscript files on line 1. They aren't traces produced by my code. Anyone know why param:Result traces undefined?

The documentation on webservices with FMS2 leaves a bit to be desired. My example was based on the?code samples of in the live docs.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读