Implementing DOTNET non-chained factory mode through web services using Ajax technology

Source: Internet
Author: User

1. Other consistent entry points for Web Services: int execute (Dataset DS );
2. Implement the non-chained factory model and dynamically load service providers to provide services.

1   Public   Static   Int Execute (Dataset DS) {
2
3 String [] Arr = Unpack (DS );
4
5 // Analysis and invoke right method
6 String Methodname = Arr [ 0 ]. Tostring (). Trim ();
7 Object [] Parme =   New   Object [] {
8System. int32.parse (ARR [1]. Tostring (). Trim ()),
9System. int32.parse (ARR [2]. Tostring (). Trim ())
10} ;
11
12 Assembly oassembly =   Null ;
13 Type otype =   Null ;
14
15
16 Oassembly = Assembly. getexecutingassembly ();
17 Otype = Oassembly. GetType (methodname );
18
19 Mycompute com =   Null ;
20 Com = (Mycompute) activator. createinstance (otype );
21 // Omethod = otype. getmethod ("execute ");
22
23 // Int result = (INT) omethod. Invoke (new object (), Parme );
24 Int Result = Com. Execute (system. int32.parse (ARR [ 1 ]. Tostring (). Trim (), system. int32.parse (ARR [ 2 ]. Trim ()));
25 Return Result;
26 }
27
28 Public Static   String [] Unpack (Dataset DS)
29 {
30 If (DS =   Null ) Throw   New Exception ( " Dataset Error " );
31
32 String [] Arr =   New   String [ 3 ];
33
34 Int I =   0 ;
35
36 Foreach (Datarow row In DS. Tables [ 0 ]. Rows)
37 {
38 Foreach (Datacolumn Column In DS. Tables [ 0 ]. Columns)
39 {
40Arr [I]=Row [column]. tostring ();
41I++;
42}
43 }
44 Return Arr;
45 }
46

3. The client obtains the service result through ajax to achieve no refreshing.
[Ajax. ajaxmethod ()]
Public int getresult (string methodname, string str1, string str2)
4.

1 Function serverside ()
2 {
3 _ Default. getresult (
4 Document. getelementbyid ( " Select1 " ). Value,
5 Document. getelementbyid ( " Text1 " ). Value,
6 Document. getelementbyid ( " Text2 " ). Value, serverside_callback );
7 }
8
9 Function serverside_callback (RES) {
10 // Document. getelementbyid ("result"). value = response. value;
11 If (Res. Error ! = Null ) Alert (res. Error );
12
13 Document. getelementbyid ( " Result " ). Innerhtml = " <Font size = 3 color = Red> " + Res. Value + " </Font> " ;
14
15 }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.