FMS 调用 WEBSERVICE(1)
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_
Note that the traces such as
param:country1 UK
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?
param:country2 USA param:Result 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. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |