扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
using System; using System.Collections; using System.ComponentModel; public class SampleRow{ private string _name; private string _description; 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 Description { get { return _description; } set { _description = value; } } public SampleRow() { _id = -1; } public SampleRow(int id, string name, string description) { _id = id; _name = name; _description = description; } } |
<%@ WebService Language="C#" Class="SampleDataService" %> 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; [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class SampleDataService : DataService { static List<SampleRow> _data; static int _nextId; static object _dataLock = new object(); private static List<SampleRow> Data { get { if (_data == null) { lock (_dataLock) { if (_data == null) { _data = new List<SampleRow>(); _data.Add(new SampleRow(0, "A. Datum Corporation", "http://www.adatum.com")); _data.Add(new SampleRow(1, "Adventure Works", "http://www.adventure-works.com")); _data.Add(new SampleRow(2, "Alpine Ski House", "http://www.alpineskihouse.com")); _data.Add(new SampleRow(3, "Baldwin Museum of Science?", "http://www.baldwinmuseumofscience.com")); _data.Add(new SampleRow(4, "Blue Yonder Airlines","http://www.blueyonderairlines.com")); _data.Add(new SampleRow(5, "City Power & Light","http://www.cpandl.com")); _data.Add(new SampleRow(6, "Coho Vineyard","http://www.cohovineyard.com")); _data.Add(new SampleRow(7, "Contoso, Ltd","http://www.contoso.com")); _data.Add(new SampleRow(8, "Graphic Design Institute", "http://www.graphicdesigninstitute.com")); _nextId = 9; } } } return _data; } } [DataObjectMethod(DataObjectMethodType.Delete)] public void DeleteRow(int id) { foreach (SampleRow row in _data) { if (row.Id == id) { lock (_dataLock) { _data.Remove(row); } break; } } } [DataObjectMethod(DataObjectMethodType.Select)] public SampleRow[] SelectRows() { return SampleDataService.Data.ToArray(); } [DataObjectMethod(DataObjectMethodType.Insert)] public SampleRow InsertRow(string organization, string url) { SampleRow newRow; lock (_dataLock) { newRow = new SampleRow(_nextId++, organization, url); _data.Add(newRow); } return newRow; } [DataObjectMethod(DataObjectMethodType.Update)] public void UpdateRow(SampleRow updateRow) { foreach (SampleRow row in _data) { if (row.Id == updateRow.Id) { row.Name =updateRow.Name; row.Description = updateRow.Description; break; } } } } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者