C # improves performance of WebService interface calls

Source: Internet
Author: User

  Public classWebServiceClient {Private Objectagent; PrivateType AgentType; Private Const stringCode_namespace ="EnterpriseServerBase.WebService.DynamicWebCalling";  Publicwebserviceclient () {} Public voidShowallmethods () {methodinfo[] PME=Agenttype.getmethods (); inti =0;  while(I <PME. Length) {i++; }                    }         Public stringGetonemethod (stringmethod) {MethodInfo PME=Agenttype.getmethod (method); returnPME.        ToString (); }                  /// <summary<        ///constructor Function/// </summary<        /// <param name= "url" <</param<Public void Webserviceinit (string url)        {            //get WSDLWebClient WC =NewWebClient (); Stream Stream= WC. OpenRead (URL +"? WSDL"); ServiceDescription SD=Servicedescription.read (stream); ServiceDescriptionImporter SDI=NewServiceDescriptionImporter (); Sdi. Addservicedescription (SD,"",""); CodeNamespace cn=NewCodeNamespace (code_namespace); //Generate the client proxy class codeCodeCompileUnit CCU =NewCodeCompileUnit (); Ccu.            Namespaces.add (CN); Sdi.            Import (CN, CCU); CSharpCodeProvider ICC=NewCSharpCodeProvider (); //Setting Compilation ParametersCompilerParameters cplist =NewCompilerParameters (); 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"); //Compiling proxy classesCompilerResults CR =icc.compileassemblyfromdom (cplist, CCU); if(true==Cr. errors.haserrors) {System.Text.StringBuilder sb=NewSystem.Text.StringBuilder (); foreach(System.CodeDom.Compiler.CompilerError CEinchCr. Errors) {sb. Append (CE.                    ToString ()); Sb.                Append (System.Environment.NewLine); }                Throw NewException (sb.)            ToString ()); } AgentType= Cr.CompiledAssembly.GetTypes () [0]; Agent=Activator.CreateInstance (AgentType); }            ///<summary<        ///invokes the specified method///</summary<        ///<param name= "MethodName" < method name, case sensitive </param<        ///<param name= "args" < parameters, assigning values in order of parameters </param<        ///return value of <returns<web service </returns<Public Object Invoke1 (String methodName, params object[] args){MethodInfo mi=Agenttype.getmethod (methodName); return  This.        Invoke2 (MI, args); }          ///<summary<        ///call the specified method///</summary<        ///<param Name= "method" < information </param<        ///<param name= "args" < parameters, assigning values in order of parameters </param<        ///return value of <returns<web service </returns<Public Object Invoke2 (MethodInfo method, params object[] args)        {              returnmethod.          Invoke (agent, args); }           Public ObjectWebservicecall (stringFunction,Object[] paramvalue) {                        Objectactual = This.            Invoke1 (Function, paramvalue); returnactual; }    }

Create a global WebServiceClient instance, initialize the server URL at the appropriate time, and increase the speed by not having to request a URL address repeatedly when making webservice calls

C # improves performance of WebService interface calls

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.