Front-end interface Background:
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; NA Mespace 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 ("direct call" + strvalue) ;}, null); SC. invokeoperation ("getunittype", typeof (Ienumerable <string>), new dictionary <string, object >{{ "unit", 1 },{ "cmdype", "admin" },{ "starttime", datetime. now. adddays (-20)}, {"endtime", datetime. now }}, true, evv =>{ if (! Evv. haserror) {var SD = evv. value; MessageBox. show ("INVOKE" + SD. tostring () ;}}, null);/* you can use the built-in observablecollection class to create a data source set in Silverlight. Because the observablecollection class implements the inotifypropertychanged interface, the inotifycollectionchanged interface is also implemented. The observablecollection class can not only implement add, remove, clear, and insert operations, but also trigger the propertychanged event. */Observablecollection <student> stulist = new observablecollection <student> (); SC. getstudentbyname ("Ye Wei", ye => {If (! Ye. haserror) {stulist = (observablecollection <student>) ye. value ;}}, null); SC. invokeoperation ("getstudentbyname", typeof (observablecollection <student>), new dictionary <string, object >{{ "name", "Ye Shuo" }}, 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 );}}}
View code
Ria service method:
Namespace silverlightriaservice. web {using system; using system. collections. generic; using system. LINQ; using system. web; using system. servicemodel; using system. servicemodel. domainservices. hosting; using system. servicemodel. domainservices. server; [enableclientaccess ()] public class serviceclass: domainservice {Public String getunittype (INT unit, string cmdype, datetime starttime, datetime endtime) {return unit + cmdype + starttime + endtime ;} public ienumerable <student> getstudentbyname (string name) {list <student> List = new list <student> (); list. add (new student () {studentname = Name, sex = "male"}); return list ;}}}
View code
Add web config:
<? XML version = "1.0" encoding = "UTF-8"?> <! -- For more information about how to configure ASP. NET applications, visit the http://go.microsoft.com/fwlink? Linkid = 169433 --> <configuration> <system. webserver> <modules runallmanagedmodulesforallrequests = "true"> <Add name = "domainservicemodule" precondition = "managedhandler" type = "system. servicemodel. domainservices. hosting. domainservicehttpmodule, system. servicemodel. domainservices. hosting, version = 4.0.0.0, culture = neutral, publickeytoken = 31bf3856ad364e35 "/> </modules> <validateintegratedmodeconfiguration =" false "/> </system. webserver> <system. web> View code
Call methods in the RIA Service