web123456

C# calls third-party WSDL interface

 public static object InvokeWebService02(string url, string methodname, object[] args)
        {
//The namespace here is the webservices that need to be referencedNamespace, you can also add a parameter to pass it in from outside.
            string @namespace = "MyWebserviceTest";
             Console.WriteLine("Define namespace: " + @namespace);
            try
            {
("Start to getwsdl...");
//Get WSDL
                WebClient wc = new WebClient();
("Start to get streaming data...");
                Stream stream = (url + "?wsdl");

                ServiceDescription sd = (stream);
("Format streaming data...");
                string classname = [0].Name;
("Get service[0].name:" + classname);
                ServiceDescriptionImporter sdi = new ServiceDescriptionImporter();
("Create an instance of the generated proxy class function class object...");
                (sd, "", "");
                = "SOAP";
("The protocol for configuring access to XML is: " + );
("Add stream data to the instance...");
                CodeNamespace cn = new CodeNamespace(@namespace);
("Generate namespace object...");


//Generate client proxy class code
                CodeCompileUnit ccu = new CodeCompileUnit();
("Create CodeDom container object...");
                (cn);
("Add a namespace to the container...");
                (cn, ccu);
("Import namespaces and containers into wsdl stream...");
                CSharpCodeProvider csc = new CSharpCodeProvider();
("Create C# codeGeneratorand compiler objects...");
                //ICodeCompiler icc = ();
//Set the compilation parameters
                CompilerParameters cplist = new CompilerParameters();
("Set the compilation parameters...");
                = false;
                = true;
                ("");
                ("");
                ("");
                ("");
//The field OutputAsembly can be configured or not, after configuration, the followingCompilerThe object will generate wsdl .dll file according to the configured path
                = () + "\\" + classname + ".dll";
("Compile and generate proxy class objects according to the compiler object according to the compiler object and container object settings...");
//Compile the proxy class
                CompilerResults cr = (cplist, ccu);

("Compilation is completed...");
("Detection of errors in compilation...");
                if ((() + "\\" + classname + ".dll"))
                {
(classname + ".dll" + "File Generation...");
                }
                if (true == )
                {
                    sb = new ();
                    foreach ( ce in )
                    {
                        (());
                        ();
                    }
                    throw new Exception(());
                }

("Start calling the compiled assembly...");
("Create assembly object...");
                assembly = (classname + ".dll");
                Type t = (@namespace + "." + classname, true, true);
("Get assembly" + @namespace + "." + classname + "Type object in...");
                object obj = (t);
("Create an instance of this object..."+obj);
                mi = (methodname);
("Get information about a method named " + methodname + "....\n" + ());
("Start calling this method...");
                return (obj, args);
            }
            catch (Exception ex)
            {
("WebService call exception, detailed information is as follows: {0}", ());
                return null;
            }
        }