wsdl Webサービスからキーと値のペアを取得して、Flexでデータのリストを表示する方法は? 助けてください。
1 に答える
0
これは、Web サービスとそれが提供するデータ型によって異なります。多くの Web サービスは、応答をオブジェクトのリストとして返すことができます。構造化された文字列を提供するものもあります。
この例では、XML を文字列として返す単純な公共の天気 Web サービスを使用します。
これはサービスの説明です: http://www.webservicex.com/globalweather.asmx?wsdl これはテストページです: http://www.webservicex.com/globalweather.asmx?test
GetCitiesByCountry メソッドを使用して、このリストを取得します。
//ソースコード
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955" minHeight="600" creationComplete="init()">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.rpc.CallResponder;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import services.globalweather.Globalweather;
private var ws:Globalweather = new Globalweather();
private var getCitiesByCountryCR:CallResponder;
private function init():void
{
getCitiesByCountryCR = new CallResponder();
getCitiesByCountryCR.addEventListener(ResultEvent.RESULT, onResult);
getCitiesByCountryCR.addEventListener(FaultEvent.FAULT, onFault);
}
private function onResult(evt:ResultEvent):void
{
var xml:XML = new XML(evt.result);
var xmlList:XMLList = xml.Table.City;
taCities.text = "";
for each (var item:XML in xmlList)
{
taCities.text += item.toString() + String.fromCharCode(13);
}
}
private function onFault(evt:FaultEvent):void
{
Alert.show("Fault!");
}
protected function getCities(event:MouseEvent):void
{
getCitiesByCountryCR.token = ws.GetCitiesByCountry(tiCountry.text);
}
]]>
</fx:Script>
<s:VGroup x="20" y="20" width="330" height="200">
<s:HGroup verticalAlign="bottom">
<s:Label text="Enter country name:"/>
<s:TextInput id="tiCountry" text="France"/>
<s:Button x="202" y="10" label="Get cities!" click="getCities(event)"/>
</s:HGroup>
<s:TextArea id="taCities" height="100%" width="100%"/>
</s:VGroup>
</s:Application>
于 2013-03-16T22:54:17.533 に答える