前端界面后台:
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using System.ServiceModel.DomainServices.Client; using System.Collections.ObjectModel; using SilverlightRiaService.Web; namespace SilverlightRiaService { public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); ServiceClass sc = new ServiceClass(); sc.GetUnitType(1, "admin", DateTime.Now.AddDays(-20), DateTime.Now, o => { if (o.HasError) { MessageBox.Show("error"); } else { string strvalue = o.Value; MessageBox.Show("直接调" + strvalue); } }, null); sc.InvokeOperation("GetUnitType", typeof(IEnumerable<string>), new Dictionary<string, object> { { "unit", 1 }, { "systype", "admin" }, { "startTime", DateTime.Now.AddDays(-20) }, { "endTime", DateTime.Now } }, true, evv => { if (!evv.HasError) { var sd = evv.Value; MessageBox.Show("Invoke" + sd.ToString()); } }, null); /* 在Silverlight中创建数据源集合可以使用内建的ObservableCollection类, 因为ObservableCollection类既实现了INotifyPropertyChanged接口,又实现了INotifyCollectionChanged接口。 使用ObservableCollection类不但可以实现Add、Remove、Clear和Insert操作,还可以触发PropertyChanged事件。 */ ObservableCollection<Student> stulist = new ObservableCollection<Student>(); sc.GetStudentByName("叶薇", ye => { if (!ye.HasError) { stulist = (ObservableCollection<Student>)ye.Value; } }, null); sc.InvokeOperation("GetStudentByName", typeof(ObservableCollection<Student>), new Dictionary<string, object> { { "name", "叶朔" } }, true, shuo => { if (!shuo.HasError) { stulist = new ObservableCollection<Student>(shuo.Value as IEnumerable<Student>); List<Student> sdstulist = new List<Student>(shuo.Value as IEnumerable<Student>); } }, null); } } }