/// <summary>
        /// 动态调用WebService
        /// </summary>
        /// <param name="request">WebService请求参数</param>
        /// <returns>object</returns>
        public static object InvokeWebService(this WebServiceRequest request)
        {
            var cr = request.GetCompilerResults();

            if (cr == null)
            {
                return(null);
            }

            //生成代理实例,并调用方法
            var assembly = cr.CompiledAssembly;
            var t        = assembly.GetType(request.NameSpace + "." + request.ClassName, true, true);
            var obj      = Activator.CreateInstance(t);
            var mi       = t.GetMethod(request.MethodName);

            return(mi.Invoke(obj, request.Args));
        }
        private static CompilerResults GetCompilerResults(this WebServiceRequest request)
        {
            if (request == null)
            {
                return(null);
            }
            if (string.IsNullOrEmpty(request.ClassName))
            {
                request.ClassName = GetClassName(request.Url);
            }
            var strUrl = string.Format("{0}?wsdl", request.Url);

            if (htWebService.ContainsKey(strUrl))
            {
                return(htWebService[strUrl]);
            }


            //获取服务描述语言(WSDL)
            var wc = new WebClient();

            var stream = wc.OpenRead(strUrl);

            if (stream == null)
            {
                return(null);
            }

            var sd  = ServiceDescription.Read(stream);
            var sdi = new ServiceDescriptionImporter();

            sdi.AddServiceDescription(sd, "", "");
            var cn = new CodeNamespace(request.NameSpace);

            //生成客户端代理类代码
            var ccu = new CodeCompileUnit();

            ccu.Namespaces.Add(cn);
            sdi.Import(cn, ccu);
            var csc = new CSharpCodeProvider();
            var icc = csc.CreateCompiler();

            //设定编译器的参数
            var cplist = new CompilerParameters {
                GenerateExecutable = false, 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");

            //编译代理类
            var cr = icc.CompileAssemblyFromDom(cplist, ccu);

            if (cr.Errors.HasErrors)
            {
                var sb = new StringBuilder();
                foreach (CompilerError ce in cr.Errors)
                {
                    sb.Append(ce);
                    sb.Append(Environment.NewLine);
                }
                throw new Exception(sb.ToString());
            }

            htWebService.Add(strUrl, cr);
            return(cr);
        }