Flex读取XML文件内容,和webservice交互
这段时间学了点Flex的东西,做了个案例:
1
<?xml version="1.0" encoding="utf-8"?>
2
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundAlpha="0" initialize="myService.send();" fontSize="13">
3
<mx:Script>
4
<![CDATA[
5
import mx.controls.Alert;
6
import mx.rpc.events.ResultEvent;
7
import mx.collections.ArrayCollection;
8
9
private function resultHandler(event:ResultEvent):void {
10
WS.wsdl = event.result.WebServiceUrl.LocalUrl.value;
11
WS.GetProductGroup.send();
12
}
13
private function SetStock(e:ResultEvent):void
14
{
15
areachart1.dataProvider = e.result as ArrayCollection;
16
WS.GetPriceFromGroup.send();
17
}
18
private function SetPrice(e:ResultEvent):void
19
{
20
line1.dataProvider = e.result as ArrayCollection;
21
}
22
private function BindComboBox(e:ResultEvent):void
23
{
24
cbxProductID.dataProvider = e.result as ArrayCollection;
25
WS.GetStockFromProductGroup.send();
26
}
27
private function BindAreaChart():void
28
{
29
WS.GetStockFromProductGroup.send();//Alert.show(cbxProductID.selectedItem.ProductID.toString());
30
}
31
]]>
32
</mx:Script>
33
<mx:Panel y="43" width="100%" height="100%" backgroundAlpha="0" layout="absolute" horizontalCenter="0" fontSize="12"
34
title="LME、SHFE、Comex、LME三月价格叠加图表">
35
<mx:AreaChart y="0" id="areachart1" height="100%" width="100%" fontSize="12" x="0">
36
<mx:horizontalAxis>
37
<!--<mx:CategoryAxis categoryField="LmeTDate"/>-->
38
<mx:DateTimeAxis dataUnits="days" displayLocalTime="true" interval="70" />
39
</mx:horizontalAxis>
40
<mx:verticalAxis>
41
<mx:LinearAxis title=""/>
42
</mx:verticalAxis>
43
<mx:secondVerticalAxis>
44
<mx:LinearAxis title=""/>
45
</mx:secondVerticalAxis>
46
<mx:series>
47
<mx:AreaSeries displayName="LME库存" yField="LMEStock" xField="Date"/>
48
<mx:AreaSeries displayName="Comex库存" yField="ComexStock" xField="Date"/>
49
<mx:AreaSeries displayName="SHFE库存" yField="SHFEStock" xField="Date"/>
50
</mx:series>
51
<mx:secondSeries>
52
<mx:LineSeries id="line1" yField="Price" xField="Date" form="curve" displayName="LME三月价格">
53
<mx:lineStroke>
54
<mx:Stroke weight="1" alpha="1"/>
55
</mx:lineStroke>
56
</mx:LineSeries>
57
</mx:secondSeries>
58
</mx:AreaChart>
59
<mx:Legend dataProvider="{areachart1}" y="10" direction="vertical" fontSize="35" fontWeight="normal"
60
alpha="1.0" backgroundAlpha="1.0" cornerRadius="0" borderStyle="none" fontFamily="Verdana" x="80"/>
61
</mx:Panel>
62
<mx:HTTPService id="myService" url="WebServiceUrl.xml" result="{resultHandler(event);}"/>
63
<mx:WebService id="WS" fault="Alert.show(event.fault.faultString, 'Error')" showBusyCursor="true">
64
<mx:operation name="GetProductGroup" resultFormat="object" result="BindComboBox(event);"/>
65
<mx:operation name="GetStockFromProductGroup" resultFormat="object" result="SetStock(event);">
66
<mx:request xmlns="">
67
<ProductGroup>
68
{cbxProductID.selectedItem.Group}
69
</ProductGroup>
70
</mx:request>
71
</mx:operation>
72
<mx:operation name="GetPriceFromGroup" resultFormat="object" result="SetPrice(event);">
73
<mx:request xmlns="">
74
<group>
75
{cbxProductID.selectedItem.Group}
76
</group>
77
</mx:request>
78
</mx:operation>
79
</mx:WebService>
80
<mx:ComboBox x="84" y="10" id="cbxProductID" change="BindAreaChart();" labelField="ProductName"
81
openDuration="250" closeDuration="250"></mx:ComboBox>
82
<mx:Label x="0" y="13" text="请选择产品:"/>
83
</mx:Application>
84
<?xml version="1.0" encoding="utf-8"?>2
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundAlpha="0" initialize="myService.send();" fontSize="13">3
<mx:Script>4
<![CDATA[5
import mx.controls.Alert;6
import mx.rpc.events.ResultEvent;7
import mx.collections.ArrayCollection;8
9
private function resultHandler(event:ResultEvent):void {10
WS.wsdl = event.result.WebServiceUrl.LocalUrl.value;11
WS.GetProductGroup.send();12
}13
private function SetStock(e:ResultEvent):void14
{15
areachart1.dataProvider = e.result as ArrayCollection;16
WS.GetPriceFromGroup.send();17
}18
private function SetPrice(e:ResultEvent):void19
{20
line1.dataProvider = e.result as ArrayCollection;21
}22
private function BindComboBox(e:ResultEvent):void23
{24
cbxProductID.dataProvider = e.result as ArrayCollection;25
WS.GetStockFromProductGroup.send();26
}27
private function BindAreaChart():void28
{29
WS.GetStockFromProductGroup.send();//Alert.show(cbxProductID.selectedItem.ProductID.toString());30
}31
]]>32
</mx:Script>33
<mx:Panel y="43" width="100%" height="100%" backgroundAlpha="0" layout="absolute" horizontalCenter="0" fontSize="12"34
title="LME、SHFE、Comex、LME三月价格叠加图表">35
<mx:AreaChart y="0" id="areachart1" height="100%" width="100%" fontSize="12" x="0">36
<mx:horizontalAxis>37
<!--<mx:CategoryAxis categoryField="LmeTDate"/>-->38
<mx:DateTimeAxis dataUnits="days" displayLocalTime="true" interval="70" />39
</mx:horizontalAxis>40
<mx:verticalAxis>41
<mx:LinearAxis title=""/>42
</mx:verticalAxis>43
<mx:secondVerticalAxis>44
<mx:LinearAxis title=""/>45
</mx:secondVerticalAxis>46
<mx:series>47
<mx:AreaSeries displayName="LME库存" yField="LMEStock" xField="Date"/>48
<mx:AreaSeries displayName="Comex库存" yField="ComexStock" xField="Date"/>49
<mx:AreaSeries displayName="SHFE库存" yField="SHFEStock" xField="Date"/>50
</mx:series>51
<mx:secondSeries>52
<mx:LineSeries id="line1" yField="Price" xField="Date" form="curve" displayName="LME三月价格">53
<mx:lineStroke>54
<mx:Stroke weight="1" alpha="1"/>55
</mx:lineStroke>56
</mx:LineSeries>57
</mx:secondSeries>58
</mx:AreaChart>59
<mx:Legend dataProvider="{areachart1}" y="10" direction="vertical" fontSize="35" fontWeight="normal"60
alpha="1.0" backgroundAlpha="1.0" cornerRadius="0" borderStyle="none" fontFamily="Verdana" x="80"/>61
</mx:Panel>62
<mx:HTTPService id="myService" url="WebServiceUrl.xml" result="{resultHandler(event);}"/>63
<mx:WebService id="WS" fault="Alert.show(event.fault.faultString, 'Error')" showBusyCursor="true">64
<mx:operation name="GetProductGroup" resultFormat="object" result="BindComboBox(event);"/>65
<mx:operation name="GetStockFromProductGroup" resultFormat="object" result="SetStock(event);">66
<mx:request xmlns="">67
<ProductGroup>68
{cbxProductID.selectedItem.Group}69
</ProductGroup>70
</mx:request>71
</mx:operation>72
<mx:operation name="GetPriceFromGroup" resultFormat="object" result="SetPrice(event);">73
<mx:request xmlns="">74
<group>75
{cbxProductID.selectedItem.Group}76
</group>77
</mx:request>78
</mx:operation>79
</mx:WebService>80
<mx:ComboBox x="84" y="10" id="cbxProductID" change="BindAreaChart();" labelField="ProductName"81
openDuration="250" closeDuration="250"></mx:ComboBox>82
<mx:Label x="0" y="13" text="请选择产品:"/>83
</mx:Application>84

下面是webservice代码:
1
using System;
2
using System.Collections;
3
using System.ComponentModel;
4
using System.Data;
5
using System.Web;
6
using System.Web.Services;
7
using System.Web.Services.Protocols;
8
using System.Data.OleDb;
9
using System.Data.SqlClient;
10
using FDPS.Entity;
11
using FDPS.Provider.Factory;
12
using FDPS.Provider.SqlClient;
13
using System.Collections.Generic;
14
15
namespace FlexDataProvideService.WebService
16
{
17
/// <summary>
18
/// FirstFlexAppData 的摘要说明
19
/// </summary>
20
[WebService(Namespace = "http://tempuri.org/")]
21
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
22
[ToolboxItem(false)]
23
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
24
// [System.Web.Script.Services.ScriptService]
25
public class FirstFlexAppData : System.Web.Services.WebService
26
{
27
28
[WebMethod]
29
public string HelloWorld()
30
{
31
return "Hello World";
32
}
33
34
获取上海/LME铜比价
66
67
根据产品ID获取库存数据
93
94
获取产品组和名称
120
121
根据产品组获取价格
140
141
根据产品分组获取SHFE、LME、Comex产品库存
164
165
获取所有市场
182
183
根据市场ID获取产品
206
207
铜比价
217
218
库存
230
231
市场
238
239
产品
246
247
public class ProductGroup
248
{
249
public string ProductName;
250
public string Group;
251
}
252
253
public class PriceGroup
254
{
255
public string Date;
256
public string Price;
257
}
258
259
LME、SHFE、Comex、LME三个月价格叠加图表数据类
268
}
269
}
270
using System;2
using System.Collections;3
using System.ComponentModel;4
using System.Data;5
using System.Web;6
using System.Web.Services;7
using System.Web.Services.Protocols;8
using System.Data.OleDb;9
using System.Data.SqlClient;10
using FDPS.Entity;11
using FDPS.Provider.Factory;12
using FDPS.Provider.SqlClient;13
using System.Collections.Generic;14

15
namespace FlexDataProvideService.WebService16
{17
/// <summary>18
/// FirstFlexAppData 的摘要说明19
/// </summary>20
[WebService(Namespace = "http://tempuri.org/")]21
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]22
[ToolboxItem(false)]23
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。24
// [System.Web.Script.Services.ScriptService]25
public class FirstFlexAppData : System.Web.Services.WebService26
{27

28
[WebMethod]29
public string HelloWorld()30
{31
return "Hello World";32
}33

34
获取上海/LME铜比价66

67
根据产品ID获取库存数据93

94
获取产品组和名称120

121
根据产品组获取价格140

141
根据产品分组获取SHFE、LME、Comex产品库存164

165
获取所有市场182

183
根据市场ID获取产品206

207
铜比价217

218
库存230

231
市场238

239
产品246

247
public class ProductGroup248
{249
public string ProductName;250
public string Group;251
}252

253
public class PriceGroup254
{255
public string Date;256
public string Price;257
}258

259
LME、SHFE、Comex、LME三个月价格叠加图表数据类268
}269
}270

以下是XML文件内容:
<?xml version="1.0" encoding="utf-8"?>
<WebServiceUrl>
<item>
<value>http://172.20.67.231/WebService/ProductOrderWebService.asmx?WSDL</value>
</item>
<LocalUrl>
<value>http://localhost:8081/WebService/FirstFlexAppData.asmx?WSDL</value>
</LocalUrl>
</WebServiceUrl>
运行效果:


浙公网安备 33010602011771号