Web Service using System; using SystemCollections; using SystemCollectionsGeneric; using SystemComponentModel; using SystemIO; using SystemWeb; using SystemWebCaching; using SystemWebServices; using SystemWebServicesProtocols; using MicrosoftWebServices;
// // For simplicity this example demonstraes storing and manipulating // the data objects in memory A database can also be used //
[WebService(Namespace = )] [WebServiceBinding(ConformsTo = WsiProfilesBasicProfile_)] public class MyDataService : DataService { static List _data; static object _dataLock = new object();
private static List Data { get { if (_data == null) { lock (_dataLock) { if (_data == null) { _data = new List(); for (int i = ; i < ; i++) { _dataAdd(new Entry(iDflying + iToString() stringFormat(Dflying{} iToString()))); } } } } return _data; } }
[DataObjectMethod(DataObjectMethodTypeSelect)] public Entry[] SelectRows() { return MyDataServiceDataToArray(); } }
public class Entry { private string _name; private string _email; private int _id;
[DataObjectField(true true)] public int Id { get { return _id; } set { _id = value; } }
[DataObjectField(false)] [DefaultValue(New row)] public string Name { get { return _name; } set { _name = value; } }
[DataObjectField(false)] [DefaultValue()] public string Email { get { return _email; } set { _email = value; } }
public Entry() { _id = ; }
public Entry(int id string name string description) { _id = id; _name = name; _email = description; } } 然後在ASPX頁面中我們需要考慮並定義如下四部分的內容