Flex 3 Call .Net WebService (3)
Flex 3 程式碼如下
分別測試跟呼叫之下的 Web Service
程式碼如下:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Button x="75" y="52" label="Add a data." click="btnInsert_Clidk();" width="133"/>
<mx:Script>
<![CDATA[
import generated.webservices.GetUserInfoCount_request;
import generated.webservices.GetUserInfoCountResultEvent;
import generated.webservices.ArrayOfUserInfo;
import mx.collections.ArrayCollection;
import generated.webservices.GetUserInfoArrayResultEvent;
import generated.webservices.AddUserInfoResultEvent;
import generated.webservices.AddUserInfo_request;
import generated.webservices.TestService;
import generated.webservices.UserInfo;
import mx.controls.*;
// TestService
private var objService:TestService=new TestService();
public function btnInsert_Clidk():void
{
objService.addaddUserInfoEventListener(resultAddUserInfo);
//新增一筆資料 呼叫 WebService 中的 AddUserInfo(string name,string tel,string addr)
objService.addUserInfo("Lucifer.Loudon","0917796416","台北市內湖區");
}
//取回結果並用Alet.show方式秀出
public function resultAddUserInfo(evt:AddUserInfoResultEvent):void
{
Alert.show("Name:" + evt.result.Name +", Tel:"+ evt.result.Tel+", Addr:"+evt.result.Addr);
}
public function btnGetAllData_Click():void
{
objService.addgetUserInfoArrayEventListener(resultGetUserInfo);
//呼叫 UserInfo[] GetUserInfoArray()
objService.getUserInfoArray_send();
}
public function resultGetUserInfo(evt:GetUserInfoArrayResultEvent):void
{
var list:ArrayCollection = evt.result as ArrayCollection ;
dg.dataProvider=list;
}
public function btnGetArrayCount_Click():void
{
var list:ArrayOfUserInfo=new ArrayOfUserInfo();
for(var i:int=1;i<=20;i++)
{
var tmp:UserInfo=new UserInfo();
tmp.Name="Name"+i.toString();
tmp.Tel="TEL"+i.toString();
tmp.Addr="Addr"+i.toString();
list.addItem(tmp);
}
//呼叫 GetUserInfoCount(UserInfo[] userInfos) 並傳入 UserInfo[20]
objService.addgetUserInfoCountEventListener(resultGetArrayCount);
objService.getUserInfoCount(list);
}
public function resultGetArrayCount(evt:GetUserInfoCountResultEvent):void
{
Alert.show(String(evt.result));
}
]]>
</mx:Script>
<mx:Button x="75" y="106" label="Get AllDataInfo" width="133" id="btnGetAllData" click="btnGetAllData_Click()"/>
<mx:DataGrid x="75" y="179" width="399" height="258" id="dg">
<mx:columns>
<mx:DataGridColumn headerText="Name" dataField="Name"/>
<mx:DataGridColumn headerText="Tel" dataField="Tel"/>
<mx:DataGridColumn headerText="Addr" dataField="Addr"/>
</mx:columns>
</mx:DataGrid>
<mx:Button x="242" y="52" label="Get Array Count" width="138" id="btnGetArrayCount" click="btnGetArrayCount_Click()"/>
</mx:Application>
標籤:
C#,
Flex,
WebService
|
This entry was posted on 下午5:22
and is filed under
C#
,
Flex
,
WebService
.
You can follow any responses to this entry through
the RSS 2.0 feed.
You can leave a response,
or trackback from your own site.
0 意見:
張貼留言