1. Common static call method, which can be changed by the URL address
Localhost. WebService Ws = new localhost. WebService ();
WS. url = "new URL ";
WS. helloworld ();
2. Dynamic calling with low performance
-
- /// <Summary>
-
- /// Dynamic Web Service proxy method
-
- /// </Summary>
-
- /// <Param name = "@ namespace"> name of the input space </param>
- /// <Param name = "url"> input URL parameters </param>
-
- /// <Param name = "classname"> input class name </param>
-
- /// <Param name = "methodname"> input method name </param>
-
- /// <Param name = "ARGs"> input parameter. this parameter is an ordered parameter. </param>
- Public ObjectInvokewebservice (StringURL,String@Namespace,StringClassname,StringMethodname,Object[] ARGs)
-
- {
-
- Try
-
- {
- System. net. WebClient WC =NewSystem. net. WebClient ();
-
- System. Io. Stream stream = WC. openread (URL +"? WSDL");
-
- System. Web. Services. description. servicedescription SD = system. Web. Services. description. servicedescription. Read (Stream );
- System. Web. Services. description. servicedescriptionimporter SDI =NewSystem. Web. Services. description. servicedescriptionimporter ();
-
- SDI. addservicedescription (SD,"","");
-
- System. codedom. codenamespace Cn =NewSystem. codedom. codenamespace (@Namespace);
- System. codedom. codecompileunit CCU =NewSystem. codedom. codecompileunit ();
-
- CCU. namespaces. Add (CN );
-
- SDI. Import (CN, CCU );
-
-
- Microsoft. CSHARP. csharpcodeprovider CSC =NewMicrosoft. CSHARP. csharpcodeprovider ();
- System. codedom. compiler. icodecompiler ICC = CSC. createcompiler ();
-
-
- System. codedom. compiler. compilerparameters cplist =NewSystem. codedom. compiler. compilerparameters ();
-
- Cplist. generateexecutable =False;
- Cplist. generateinmemory =True;
-
- Cplist. referencedassemblies. Add ("System. dll");
-
- Cplist. referencedassemblies. Add ("System. xml. dll");
-
- Cplist. referencedassemblies. Add ("System. Web. Services. dll");
- Cplist. referencedassemblies. Add ("System. Data. dll");
-
-
- System. codedom. compiler. compilerresults Cr = ICC. compileassemblyfromdom (cplist, CCU );
-
- If(True= Cr. errors. haserrors)
-
- {
- System. Text. stringbuilder sb =NewSystem. Text. stringbuilder ();
-
- Foreach(System. codedom. compiler. compilererror CEInCr. Errors)
-
- {
-
- SB. append (Ce. tostring ());
- SB. append (system. environment. newline );
-
- }
-
- Throw NewException (sb. tostring ());
-
- }
- System. reflection. Assembly = Cr. compiledassembly;
-
- Type T = assembly. GetType (@Namespace+"."+ Classname,True,True);
-
- ObjectOBJ = activator. createinstance (t );
- System. reflection. methodinfo MI = T. getmethod (methodname );
-
- ReturnMi. Invoke (OBJ, argS );
-
- }
-
- Catch(Exception ex)
-
- {
- Throw NewException (ex. innerexception. Message,NewException (ex. innerexception. stacktrace ));
-
- }
-
- }
-