Flex 3 Call .Net WebService (1)
首先我們得先建立WebService ..
開啟VS.Net ...
並且建立一個 Class 為
public class UserInfo
{
public string Name{get;set;} //姓名
public string Tel{get;set;} // 電話
public string Addr{get;set;} //地址
}
並建立下述的WebService 以提供測試
我直接原程式碼Po上...
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
namespace TestFlexWebService
{
/// <summary>
///Service1 的摘要描述
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
// 若要允許使用 ASP.NET AJAX 從指令碼呼叫此 Web 服務,請取消註解下一行。
// [System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
/// <summary>
/// 一個暫存的ArrayList 提供 GetUserInfoArray() 所使用
/// </summary>
public static ArrayList PubList = new ArrayList();
/// <summary>
/// 新增一個UserInfo 至 PubList 中 並且回傳回去
/// </summary>
/// <param name="name">UserInfo的Name</param>
/// <param name="tel">UserInfo的Tel</param>
/// <param name="addr">UserInfo的Addr</param>
/// <returns>回傳回去一個UserInfo的物件</returns>
[WebMethod]
public UserInfo AddUserInfo(string name,string tel,string addr)
{
UserInfo res = new UserInfo();
res.Name = name;
res.Tel = tel;
res.Addr = addr;
PubList.Add(res);
return res;
}
/// <summary>
/// 將PubList 此UserInfo Array 傳出去
/// </summary>
/// <returns>UserInfo Array</returns>
[WebMethod]
public UserInfo[] GetUserInfoArray()
{
return (UserInfo[])PubList.ToArray(typeof(UserInfo));
}
/// <summary>
/// 傳入一UserInfo Array 並回傳裡面有多少個UserInfo
/// 已測試是否.Net 此端是否可以接到到Flex傳入的UserInfo Array.
/// </summary>
/// <param name="userInfos">UserInfo Array</param>
/// <returns>Length of UserInfoArray.</returns>
[WebMethod]
public int GetUserInfoCount(UserInfo[] userInfos)
{
return userInfos.Length;
}
}
}
之後就完成了.Net WebService 這一端..
接下來就是Flex3 那邊的部份了....
標籤:
C#,
Flex,
WebService
|
This entry was posted on 下午3:24
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 意見:
張貼留言