Web Service using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.IO; using System.Web; using System.Web.Caching; using System.Web.Services; using System.Web.Services.Protocols; using Microsoft.Web.Services;
// // For simplicity this example demonstraes storing and manipulating // the data objects in memory. A database can also be used. //
[WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 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 = 0; i < 100; i++) { _data.Add(new Entry(i, "Dflying " + i.ToString(), string.Format("Dflying{0}@dflying.net", i.ToString()))); } } } } return _data; } }
[DataObjectMethod(DataObjectMethodType.Select)] public Entry[] SelectRows() { return MyDataService.Data.ToArray(); } } 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; } }