In many cases, we may very much want to customize some methods that can be called directly by the SL end. This is very useful for the design idea of SOA, because a function completes a function, this is the most common design of SOA. Here I will introduce how. Net Ria services can customize functions in SL applications.
1. Define a method on the. NET Ria service end and return a custom class. This class must have a primary key. You can use "[Key]" to identify a field as the primary key. Use the [serviceoperation] Mark for this function, so that the sliverlgiht end will come out of this function.
1: [enableclientaccess ()]
2: public class mydomainservice: domainservice
3 :{
4: [serviceoperation]
5: Public myclass mytext (string userid)
6 :{
7: myclass MC = new myclass ();
8: MC. userid = userid;
9: MC. Input = userid;
10: Return MC;
11 :}
12 :}
13:
14: public class myclass
15 :{
16: [Key]
17: Public String userid {Get; set ;}
18: Public String input {Get; set ;}
19 :}
2. The call is quite simple. The following is a Silverlight-side call.Code
1: Public home ()
2 :{
3: initializecomponent ();
4: business. Web. Services. mydomaincontext MD = new business. Web. Services. mydomaincontext ();
5: var c = md. mytext ("funsl.com ");
6: C. Completed + = new eventhandler (c_completed );
7 :}
8:
9: void c_completed (Object sender, eventargs E)
10 :{
11: var B = (system. Windows. Ria. Data. invokeoperation <business. Web. Services. myclass>) sender;
12: business. Web. Services. myclass MC = (business. Web. Services. myclass) B. value;
13: MessageBox. Show (MC. userid + ";" + MC. Input );
14 :}