当前位置: 首页>>代码示例>>C#>>正文


C# ServiceDescriptionImporter.Import方法代码示例

本文整理汇总了C#中System.Web.Services.Description.ServiceDescriptionImporter.Import方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceDescriptionImporter.Import方法的具体用法?C# ServiceDescriptionImporter.Import怎么用?C# ServiceDescriptionImporter.Import使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.Services.Description.ServiceDescriptionImporter的用法示例。


在下文中一共展示了ServiceDescriptionImporter.Import方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InvokeWebService

        public static object InvokeWebService(string url, string classname, string methodname, object[] args)
        {
            string @namespace = "EnterpriseServerBase.WebService.DynamicWebCalling";
            if ((classname == null) || (classname == ""))
            {
                classname = WebServiceProxy.GetWsClassName(url);
            }

            try
            {
                //获取WSDL
                WebClient wc = new WebClient();
                Stream stream = wc.OpenRead(url + "?WSDL");
                ServiceDescription sd = ServiceDescription.Read(stream);
                ServiceDescriptionImporter sdi = new ServiceDescriptionImporter();
                sdi.AddServiceDescription(sd, "", "");
                CodeNamespace cn = new CodeNamespace(@namespace);

                //生成客户端代理类代码
                CodeCompileUnit ccu = new CodeCompileUnit();
                ccu.Namespaces.Add(cn);
                sdi.Import(cn, ccu);
                CSharpCodeProvider csc = new CSharpCodeProvider();
                ICodeCompiler icc = csc.CreateCompiler();

                //设定编译参数
                CompilerParameters cplist = new 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");

                //编译代理类
                CompilerResults cr = icc.CompileAssemblyFromDom(cplist, ccu);
                if (true == cr.Errors.HasErrors)
                {
                    System.Text.StringBuilder sb = new System.Text.StringBuilder();
                    foreach (System.CodeDom.Compiler.CompilerError ce in cr.Errors)
                    {
                        sb.Append(ce.ToString());
                        sb.Append(System.Environment.NewLine);
                    }
                    throw new Exception(sb.ToString());
                }

                //生成代理实例,并调用方法
                System.Reflection.Assembly assembly = cr.CompiledAssembly;
                Type t = assembly.GetType(@namespace + "." + classname, true, true);
                object obj = Activator.CreateInstance(t);
                System.Reflection.MethodInfo mi = t.GetMethod(methodname);

                return mi.Invoke(obj, args);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.InnerException.Message, new Exception(ex.InnerException.StackTrace));
            }
        }
开发者ID:SLSoft,项目名称:GGZBTQPT,代码行数:60,代码来源:WebServiceProxy.cs

示例2: Invoke

        public object Invoke(string url, string methodName, string className = "", params object[] args)
        {
            if (className == null || className == "")
            {
                className = GetClassName(url);
            }

            string @namespace = "ServiceBase.WebService.DynamicWebLoad." + ProcessUrl(url);
            string cacheName = string.Format("{0}_{1}", @namespace, className);
            
            Assembly assembly = null;
            if (HttpContext.Current.Cache[cacheName] != null)
            {
                assembly = HttpContext.Current.Cache[cacheName] as Assembly;
            }
            else
            {

                //获取服务描述语言(WSDL)   
                WebClient wc = new WebClient();
                Stream stream = wc.OpenRead(url + "?WSDL");
                ServiceDescription sd = ServiceDescription.Read(stream);
                ServiceDescriptionImporter sdi = new ServiceDescriptionImporter();
                sdi.AddServiceDescription(sd, "", "");
                CodeNamespace cn = new CodeNamespace(@namespace);
                //生成客户端代理类代码   
                CodeCompileUnit ccu = new CodeCompileUnit();
                ccu.Namespaces.Add(cn);
                sdi.Import(cn, ccu);
                CSharpCodeProvider csc = new CSharpCodeProvider();
                ICodeCompiler icc = csc.CreateCompiler();
                //设定编译器的参数   
                CompilerParameters cplist = new 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");
                //编译代理类   
                CompilerResults cr = icc.CompileAssemblyFromDom(cplist, ccu);
                if (true == cr.Errors.HasErrors)
                {
                    System.Text.StringBuilder sb = new StringBuilder();
                    foreach (CompilerError ce in cr.Errors)
                    {
                        sb.Append(ce.ToString());
                        sb.Append(System.Environment.NewLine);
                    }
                    throw new Exception(sb.ToString());
                }
                //生成代理实例,并调用方法   
                assembly = cr.CompiledAssembly;
                HttpContext.Current.Cache[cacheName] = assembly;
            }
            Type t = assembly.GetType(@namespace + "." + className, true, true);
            object obj = Activator.CreateInstance(t);
            System.Reflection.MethodInfo mi = t.GetMethod(methodName);
            return mi.Invoke(obj, args);
        }
开发者ID:zhangweixing00,项目名称:SS.s,代码行数:60,代码来源:AgentService.asmx.cs

示例3: GetWebServiceAssembly

        /// <summary>
        /// get an Assembly according to wsdl path.
        /// </summary>
        /// <param name="wsdl">wsdl path</param>
        /// <param name="nameSpace">namespace</param>
        /// <returns>return Assembly</returns>
        public static Assembly GetWebServiceAssembly(string wsdl, string nameSpace)
        {
            try
            {
                System.Net.WebClient webClient = new System.Net.WebClient();
                System.IO.Stream webStream = webClient.OpenRead(wsdl);

                ServiceDescription serviceDescription = ServiceDescription.Read(webStream);
                ServiceDescriptionImporter serviceDescroptImporter = new ServiceDescriptionImporter();

                serviceDescroptImporter.AddServiceDescription(serviceDescription, "", "");
                System.CodeDom.CodeNamespace codeNameSpace = new System.CodeDom.CodeNamespace(nameSpace);
                System.CodeDom.CodeCompileUnit codeCompileUnit = new System.CodeDom.CodeCompileUnit();
                codeCompileUnit.Namespaces.Add(codeNameSpace);
                serviceDescroptImporter.Import(codeNameSpace, codeCompileUnit);

                System.CodeDom.Compiler.CodeDomProvider codeDom = new Microsoft.CSharp.CSharpCodeProvider();
                System.CodeDom.Compiler.CompilerParameters codeParameters = new System.CodeDom.Compiler.CompilerParameters();
                codeParameters.GenerateExecutable = false;
                codeParameters.GenerateInMemory = true;

                codeParameters.ReferencedAssemblies.Add("System.dll");
                codeParameters.ReferencedAssemblies.Add("System.XML.dll");
                codeParameters.ReferencedAssemblies.Add("System.Web.Services.dll");
                codeParameters.ReferencedAssemblies.Add("System.Data.dll");

                System.CodeDom.Compiler.CompilerResults compilerResults = codeDom.CompileAssemblyFromDom(codeParameters, codeCompileUnit);

                return compilerResults.CompiledAssembly;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
开发者ID:Erkan-Yilmaz,项目名称:AutomationTestFramework,代码行数:41,代码来源:WSAssembly.cs

示例4: service_info_methods

        public static void service_info_methods()
        {
            uri = new Uri("http://localhost:60377/Service1.asmx?wsdl"); 
            WebRequest webRequest = WebRequest.Create(uri);
            System.IO.Stream requestStream = webRequest.GetResponse().GetResponseStream();
            // Get a WSDL file describing a service
            ServiceDescription sd = ServiceDescription.Read(requestStream);
            string sdName = sd.Services[0].Name;

            // Initialize a service description servImport
            ServiceDescriptionImporter servImport = new ServiceDescriptionImporter();
            servImport.AddServiceDescription(sd, String.Empty, String.Empty);
            servImport.ProtocolName = "Soap";
            servImport.CodeGenerationOptions = CodeGenerationOptions.GenerateProperties;

            CodeNamespace nameSpace = new CodeNamespace();
            CodeCompileUnit codeCompileUnit = new CodeCompileUnit();
            codeCompileUnit.Namespaces.Add(nameSpace);
            // Set Warnings
            ServiceDescriptionImportWarnings warnings = servImport.Import(nameSpace, codeCompileUnit);

            if (warnings == 0)
            {
                StringWriter stringWriter = new StringWriter(System.Globalization.CultureInfo.CurrentCulture);
                Microsoft.CSharp.CSharpCodeProvider prov = new Microsoft.CSharp.CSharpCodeProvider();
                prov.GenerateCodeFromNamespace(nameSpace, stringWriter, new CodeGeneratorOptions());

                string[] assemblyReferences = new string[2] { "System.Web.Services.dll", "System.Xml.dll" };
                CompilerParameters param = new CompilerParameters(assemblyReferences);
                param.GenerateExecutable = false;
                param.GenerateInMemory = true;
                param.TreatWarningsAsErrors = false;
                param.WarningLevel = 4;

                CompilerResults results = new CompilerResults(new TempFileCollection());
                results = prov.CompileAssemblyFromDom(param, codeCompileUnit);
                Assembly assembly = results.CompiledAssembly;
                service = assembly.GetType(sdName);

                methodInfo = service.GetMethods();

                int c = 0;
                foreach (MethodInfo t in methodInfo)
                {
                    if (t.Name == "Discover")
                        break;
                    c++;
                }
                listurl = new string[c]; c = 0;
                foreach (MethodInfo t in methodInfo)
                {
                    if (t.Name == "Discover")
                        break;
                    listurl[c++] = t.Name;
                }

            }

        }
开发者ID:MinaYounan-CS,项目名称:WoT-Testbed-Environment,代码行数:59,代码来源:Service+Info.cs

示例5: Compile

        /// <summary>
        /// This is the workhorse method of the program. Given a web service type, 
        /// it generates a proxy class for it, strips out any excess types, and then 
        /// adds a few using statments to it. 
        /// </summary>
        /// <param name="type">The web service type</param>
        /// <param name="uri">The URL for the service that will be set in the constructor</param>
        private bool Compile()
        {
            try
            {
                // These next two lines do the generate the WSDL based on the web service class
                ServiceDescriptionReflector reflector = new ServiceDescriptionReflector();
                reflector.Reflect(m_type, m_uri);

                if (reflector.ServiceDescriptions.Count > 1)
                    throw new Exception(string.Format("Don't know how to deal with multiple service descriptions in {0}", m_type));

                // Now we take the WSDL service description and turn it into a proxy in CodeDOM form
                ServiceDescriptionImporter importer = new ServiceDescriptionImporter();
                importer.AddServiceDescription(reflector.ServiceDescriptions[0], null, null);
                importer.Style = m_style;

                // Probably a good idea to make the namespace a command-line parameter, but hardcode it for now
                //CodeNamespace codeNamespace = new CodeNamespace("Integic.ePower.Psd.WebServices.Common.Proxies");
                CodeCompileUnit codeCompileUnit = new CodeCompileUnit();
                codeCompileUnit.Namespaces.Add(CodeNamespace);

                ServiceDescriptionImportWarnings warnings = importer.Import(CodeNamespace, codeCompileUnit);

                // TODO: explicitly handle all of the warnings generated by the ServiceImporter
                if (warnings != 0)
                {
                    Trace.TraceError("Warnings: {1}", warnings);

                    string errorMessage;
                    switch (warnings)
                    {
                        case ServiceDescriptionImportWarnings.NoMethodsGenerated:
                            errorMessage = string.Format("Error: Web service at {0} does not contain any web methods", m_type.FullName);
                            throw new ApplicationException(errorMessage);
                        case ServiceDescriptionImportWarnings.NoCodeGenerated:
                            errorMessage = string.Format("Error: No code was generated for web service at {0}", m_type.FullName);
                            throw new ApplicationException(errorMessage);
                        default:
                            errorMessage = string.Format("Error: Unhandled error while generating code for web service {0} : {1}", m_type.FullName, warnings.ToString());
                            throw new ApplicationException(errorMessage);
                    }
                }

                if (!GenerateCode())
                    return false;

            }
            catch (Exception ex)
            {
                Errors.Add(new CompilerError(string.Empty, 0, 0, string.Empty, ex.Message));
                Trace.TraceError(ex.ToString());
                return false;
            }

            return true;

        }
开发者ID:nujmail,项目名称:xsd-to-classes,代码行数:64,代码来源:TypeProxyGenerator.cs

示例6: InvokeWebService

        /// <summary>
        /// 实例化WebServices
        /// </summary>
        /// <param name="url">WebServices地址</param>
        /// <param name="methodname">调用的方法</param>
        /// <param name="args">把webservices里需要的参数按顺序放到这个object[]里</param>
        public static object InvokeWebService(string url, string methodname, object[] args)
        {
            //这里的namespace是需引用的webservices的命名空间,我没有改过,也可以使用。也可以加一个参数从外面传进来。
            string @namespace = "client";
            try
            {
                //获取WSDL
                WebClient wc = new WebClient();
                Stream stream = wc.OpenRead(url + "?WSDL");
                ServiceDescription sd = ServiceDescription.Read(stream);
                string classname = sd.Services[0].Name;
                ServiceDescriptionImporter sdi = new ServiceDescriptionImporter();
                sdi.AddServiceDescription(sd, "", "");
                CodeNamespace cn = new CodeNamespace(@namespace);

                //生成客户端代理类代码
                CodeCompileUnit ccu = new CodeCompileUnit();
                ccu.Namespaces.Add(cn);
                sdi.Import(cn, ccu);
                CSharpCodeProvider csc = new CSharpCodeProvider();
                //ICodeCompiler icc = csc.CreateCompiler();

                //设定编译参数
                CompilerParameters cplist = new 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");

                //编译代理类
                CompilerResults cr = csc.CompileAssemblyFromDom(cplist, ccu);
                if (true == cr.Errors.HasErrors)
                {
                    System.Text.StringBuilder sb = new System.Text.StringBuilder();
                    foreach (System.CodeDom.Compiler.CompilerError ce in cr.Errors)
                    {
                        sb.Append(ce.ToString());
                        sb.Append(System.Environment.NewLine);
                    }
                    throw new Exception(sb.ToString());
                }

                //生成代理实例,并调用方法
                System.Reflection.Assembly assembly = cr.CompiledAssembly;
                Type t = assembly.GetType(@namespace + "." + classname, true, true);
                object obj = Activator.CreateInstance(t);
                System.Reflection.MethodInfo mi = t.GetMethod(methodname);

                return mi.Invoke(obj, args);
            }
            catch(Exception ex)
            {
                return ex.Message;
            }
        }
开发者ID:fqybzhangji,项目名称:Crazy,代码行数:63,代码来源:1452646768$webservice.cs

示例7: GenerateCodeFromWsdl

		CodeNamespace GenerateCodeFromWsdl (ServiceDescription sd)
		{
			ServiceDescriptionImporter imp =
				new ServiceDescriptionImporter ();
			imp.AddServiceDescription (sd, null, null);
			CodeNamespace cns = new CodeNamespace ();
			imp.Import (cns, null);
			return cns;
		}
开发者ID:nobled,项目名称:mono,代码行数:9,代码来源:ServiceDescriptionImporterTest.cs

示例8: Invoke

        public static object Invoke(string url, string className, string methodName, object[] parameters)
        {
            string compileNamespace = "Dynamic.To.Call.WebService";
            if ((className == null) || (className == ""))
            {
                className = WebServiceHelper.GetClassName(url);
            }

            //Get wsdl information
            WebClient wc = new WebClient();
            System.IO.Stream strm = wc.OpenRead(url + "?WSDL");
            ServiceDescription sd = ServiceDescription.Read(strm);
            ServiceDescriptionImporter sdi = new ServiceDescriptionImporter();
            sdi.AddServiceDescription(sd, "", "");
            CodeNamespace cn = new CodeNamespace(compileNamespace);

            //Generate client proxy class
            CodeCompileUnit ccu = new CodeCompileUnit();
            ccu.Namespaces.Add(cn);
            sdi.Import(cn, ccu);
            CSharpCodeProvider csc = new CSharpCodeProvider();
            ICodeCompiler icc = csc.CreateCompiler();

            //Setting compile parameters
            CompilerParameters compilerParams = new CompilerParameters();
            compilerParams.GenerateExecutable = false;
            compilerParams.GenerateInMemory = true;
            compilerParams.ReferencedAssemblies.Add("System.dll");
            compilerParams.ReferencedAssemblies.Add("System.XML.dll");
            compilerParams.ReferencedAssemblies.Add("System.Web.Services.dll");
            compilerParams.ReferencedAssemblies.Add("System.Data.dll");

            //compile agentcy class
            CompilerResults cr = icc.CompileAssemblyFromDom(compilerParams, ccu);
            if (true == cr.Errors.HasErrors)
            {
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                foreach (System.CodeDom.Compiler.CompilerError ce in cr.Errors)
                {
                    sb.Append(ce.ToString());
                    sb.Append(System.Environment.NewLine);
                }
                throw new Exception(sb.ToString());
            }

            //Build agent entity & call method
            System.Reflection.Assembly assembly = cr.CompiledAssembly;
            Type t = assembly.GetType(string.Concat(compileNamespace, ".", className), true, true);
            object obj = Activator.CreateInstance(t);
            System.Reflection.MethodInfo mi = t.GetMethod(methodName);
            if (parameters != null && parameters.Length > 0)
                return mi.Invoke(obj, parameters);
            else
                //Invoke(obj, BindingFlags.Default, new MyBinder(), new Object[] { (int)32, (int)32 }, CultureInfo.CurrentCulture);//ref to msdn
                return mi.Invoke(obj, BindingFlags.Default, null, null, null);
        }
开发者ID:TaylorLi,项目名称:gettogether,代码行数:56,代码来源:WebServiceHelper.cs

示例9: GetWsProxyType

 public static Type GetWsProxyType(string wsUrl, string classname)
 {
     string name = "ESBasic.WebService.DynamicWebCalling";
     if ((classname == null) || (classname == ""))
     {
         classname = GetWsClassName(wsUrl);
     }
     string key = wsUrl + "@" + classname;
     if (WSProxyTypeDictionary.ContainsKey(key))
     {
         return WSProxyTypeDictionary[key];
     }
     WebClient client = new WebClient();
     ServiceDescription serviceDescription = ServiceDescription.Read(client.OpenRead(wsUrl + "?WSDL"));
     ServiceDescriptionImporter importer = new ServiceDescriptionImporter();
     importer.AddServiceDescription(serviceDescription, "", "");
     CodeNamespace namespace2 = new CodeNamespace(name);
     CodeCompileUnit codeCompileUnit = new CodeCompileUnit();
     codeCompileUnit.Namespaces.Add(namespace2);
     importer.Import(namespace2, codeCompileUnit);
     ICodeCompiler compiler = new CSharpCodeProvider().CreateCompiler();
     CompilerParameters options = new CompilerParameters
     {
         GenerateExecutable = false,
         GenerateInMemory = true
     };
     options.ReferencedAssemblies.Add("System.dll");
     options.ReferencedAssemblies.Add("System.XML.dll");
     options.ReferencedAssemblies.Add("System.Web.Services.dll");
     options.ReferencedAssemblies.Add("System.Data.dll");
     CompilerResults results = compiler.CompileAssemblyFromDom(options, codeCompileUnit);
     if (results.Errors.HasErrors)
     {
         StringBuilder builder = new StringBuilder();
         foreach (CompilerError error in results.Errors)
         {
             builder.Append(error.ToString());
             builder.Append(Environment.NewLine);
         }
         throw new Exception(builder.ToString());
     }
     Assembly compiledAssembly = results.CompiledAssembly;
     compiledAssembly.GetTypes();
     Type type2 = compiledAssembly.GetType(name + "." + classname, true, true);
     lock (WSProxyTypeDictionary)
     {
         if (!WSProxyTypeDictionary.ContainsKey(key))
         {
             WSProxyTypeDictionary.Add(key, type2);
         }
     }
     return type2;
 }
开发者ID:JBTech,项目名称:Dot.Utility,代码行数:53,代码来源:WebServiceHelper.cs

示例10: InvokeWebServiceNew

        /// <summary>
        /// ��̬����WebService
        /// </summary>
        /// <param name="url">WebService��ַ</param>
        /// <param name="classname">����</param>
        /// <param name="methodname">������(ģ����)</param>
        /// <param name="args">�����б�</param>
        /// <returns>object</returns>
        public static object InvokeWebServiceNew(string url, string classname, string methodname, object[] args)
        {
            string @namespace = "ServiceBase.WebService.DynamicWebLoad";
            if (classname == null || classname == "")
            {
                classname = CallWebServise.GetClassName(url);
            }
            //��ȡ������������(WSDL)
            WebClient wc = new WebClient();
            Stream stream = wc.OpenRead(url + "?WSDL");
            ServiceDescription sd = ServiceDescription.Read(stream);

            ServiceDescriptionImporter sdi = new ServiceDescriptionImporter();
            sdi.AddServiceDescription(sd, "", "");

            CodeNamespace cn = new CodeNamespace(@namespace);
            //���ɿͻ��˴������
            CodeCompileUnit ccu = new CodeCompileUnit();
            ccu.Namespaces.Add(cn);
            sdi.Import(cn, ccu);

            CSharpCodeProvider csc = new CSharpCodeProvider();
            ICodeCompiler icc = csc.CreateCompiler();

            //�趨�������IJ���
            CompilerParameters cplist = new 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");
            //���������
            CompilerResults cr = icc.CompileAssemblyFromDom(cplist, ccu);

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

            //���ɴ���ʵ��,�����÷���
            System.Reflection.Assembly assembly = cr.CompiledAssembly;
            Type t = assembly.GetType(@namespace + "." + classname, true, true);
            object obj = Activator.CreateInstance(t);
            System.Reflection.MethodInfo mi = t.GetMethod(methodname);
            return mi.Invoke(obj, args);
        }
开发者ID:monkinone,项目名称:OrderPrinnt,代码行数:61,代码来源:CallWebServise.cs

示例11: BuildCodeCompileUnit

        private static CodeCompileUnit BuildCodeCompileUnit(ServiceDescriptionImporter descriptionImporter)
        {
            var codeNamespace = new CodeNamespace();
            var codeUnit = new CodeCompileUnit();
            codeUnit.Namespaces.Add(codeNamespace);

            var importWarnings = descriptionImporter.Import(codeNamespace, codeUnit);

            if (importWarnings != 0)
                throw new Exception("Invalid WSDL");

            return codeUnit;
        }
开发者ID:sadowskik,项目名称:WebServiceInvoker,代码行数:13,代码来源:CodeDomAssemblyComplier.cs

示例12: SoapHelper

        /// <summary>
        /// 动态 WebService 构造函数
        /// </summary>
        /// <param name="pUrl">WebService 地址</param>
        /// <param name="pClassname">类名,可省略,可空</param>
        public SoapHelper(string pUrl, string pClassname = null)
        {
            if (String.IsNullOrEmpty(pClassname))
                WebServiceClassname = GetWsClassName(pUrl);
            else
                WebServiceClassname = pClassname;
            WebServiceNamespace = "LiveAzure.Utility";

            try
            {
                WebClient wc = new WebClient();
                Stream stream = wc.OpenRead(pUrl + "?WSDL");
                ServiceDescription sd = ServiceDescription.Read(stream);
                ServiceDescriptionImporter sdi = new ServiceDescriptionImporter();
                sdi.AddServiceDescription(sd, "", "");
                sdi.ProtocolName = "Soap";
                sdi.Style = ServiceDescriptionImportStyle.Client;
                sdi.CodeGenerationOptions = CodeGenerationOptions.GenerateProperties | CodeGenerationOptions.GenerateNewAsync;
                CodeNamespace cn = new CodeNamespace(this.WebServiceNamespace);
                SoapCompileUnit = new CodeCompileUnit();
                SoapCompileUnit.Namespaces.Add(cn);
                sdi.Import(cn, SoapCompileUnit);

                CSharpCodeProvider csc = new CSharpCodeProvider();
                SoapCodeProvider = CodeDomProvider.CreateProvider("CSharp");
                CompilerParameters cparam = new CompilerParameters();
                cparam.GenerateExecutable = false;
                cparam.GenerateInMemory = true;
                cparam.ReferencedAssemblies.Add("System.dll");
                cparam.ReferencedAssemblies.Add("System.XML.dll");
                cparam.ReferencedAssemblies.Add("System.Web.Services.dll");
                cparam.ReferencedAssemblies.Add("System.Data.dll");

                SoapCompilerResults = SoapCodeProvider.CompileAssemblyFromDom(cparam, SoapCompileUnit);
                if (SoapCompilerResults.Errors.HasErrors)
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (CompilerError ce in SoapCompilerResults.Errors)
                    {
                        sb.Append(ce.ToString());
                        sb.Append(Environment.NewLine);
                    }
                    throw new Exception(sb.ToString());
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.InnerException.Message, new Exception(ex.InnerException.StackTrace));
            }
        }
开发者ID:NH4CL,项目名称:UniProject,代码行数:55,代码来源:SoapHelper.cs

示例13: InvokeWebService

        /// <summary>
        /// 动态调用WebService
        /// </summary>
        /// <param name="url">WebService地址</param>
        /// <param name="classname">类名</param>
        /// <param name="methodname">方法名(模块名)</param>
        /// <param name="args">参数列表</param>
        /// <returns>object</returns>
        public static object InvokeWebService(string url, string classname, string methodname, object[] args)
        {
            string @namespace = "wangsx.test";
            if (classname == null || classname == "")
            {
                classname = WebServiceHelper.GetClassName(url);
            }
            //获取服务描述语言(WSDL)
            WebClient wc = new WebClient();
            Stream stream = wc.OpenRead(url + "?WSDL");//【1】
            ServiceDescription sd = ServiceDescription.Read(stream);//【2】
            ServiceDescriptionImporter sdi = new ServiceDescriptionImporter();//【3】
            sdi.AddServiceDescription(sd, "", "");
            CodeNamespace cn = new CodeNamespace(@namespace);//【4】
            //生成客户端代理类代码
            CodeCompileUnit ccu = new CodeCompileUnit();//【5】
            ccu.Namespaces.Add(cn);
            sdi.Import(cn, ccu);
            CSharpCodeProvider csc = new CSharpCodeProvider();//【6】
            ICodeCompiler icc = csc.CreateCompiler();//【7】
            //设定编译器的参数
            CompilerParameters cplist = new CompilerParameters();//【8】
            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");
            //编译代理类
            CompilerResults cr = icc.CompileAssemblyFromDom(cplist, ccu);//【9】
            if (true == cr.Errors.HasErrors)
            {
                System.Text.StringBuilder sb = new StringBuilder();
                foreach (CompilerError ce in cr.Errors)
                {
                    sb.Append(ce.ToString());
                    sb.Append(System.Environment.NewLine);
                }
                throw new System.Exception(sb.ToString());
            }

            //生成代理实例,并调用方法
            System.Reflection.Assembly assembly = cr.CompiledAssembly;
            System.Type t = assembly.GetType(@namespace + "." + classname, true, true);
            object obj = System.Activator.CreateInstance(t);//【10】
            System.Reflection.MethodInfo mi = t.GetMethod(methodname);//【11】
            return mi.Invoke(obj, args);
        }
开发者ID:xiaolin8,项目名称:AMS,代码行数:56,代码来源:WebServiceHelper.cs

示例14: Generate

 public void Generate()
 {
     if (this.AddressType == AddressType.WebService)
     {
         string className = MethodHelper.GetClassName(this.Address);
         //Get wsdl information
         System.Net.WebClient wc = new System.Net.WebClient();
         System.IO.Stream strm = wc.OpenRead(Address + "?WSDL");
         ServiceDescription sd = ServiceDescription.Read(strm);
         ServiceDescriptionImporter sdi = new ServiceDescriptionImporter();
         sdi.AddServiceDescription(sd, "", "");
         CodeNamespace cn = new CodeNamespace(this.ComileNamespace);
         //Generate client proxy class
         CodeCompileUnit ccu = new CodeCompileUnit();
         ccu.Namespaces.Add(cn);
         sdi.Import(cn, ccu);
         CSharpCodeProvider csc = new CSharpCodeProvider();
         ICodeCompiler icc = csc.CreateCompiler();
         //Setting compile parameters
         CompilerParameters compilerParams = new CompilerParameters();
         compilerParams.GenerateExecutable = false;
         compilerParams.GenerateInMemory = true;
         compilerParams.ReferencedAssemblies.Add("System.dll");
         compilerParams.ReferencedAssemblies.Add("System.XML.dll");
         compilerParams.ReferencedAssemblies.Add("System.Web.Services.dll");
         compilerParams.ReferencedAssemblies.Add("System.Data.dll");
         //compile agentcy class
         CompilerResults cr = icc.CompileAssemblyFromDom(compilerParams, ccu);
         if (true == cr.Errors.HasErrors)
         {
             System.Text.StringBuilder sb = new System.Text.StringBuilder();
             foreach (System.CodeDom.Compiler.CompilerError ce in cr.Errors)
             {
                 sb.Append(ce.ToString());
                 sb.Append(System.Environment.NewLine);
             }
             throw new Exception(sb.ToString());
         }
         this.ProxyAssemble = cr.CompiledAssembly;
         Type t = this.ProxyAssemble.GetType(string.Concat(this.ComileNamespace, ".", className), true, true);
         ServiceObject = Activator.CreateInstance(t);
     }
     else
     {
         ServiceObject = new NormalRequest();
     }
     SetUrl(this.Address);
 }
开发者ID:TaylorLi,项目名称:gettogether,代码行数:48,代码来源:Wsdl.cs

示例15: WebServiceHelper

 public WebServiceHelper(string Url, string classname)
 {
     if ((classname == null) || (classname == string.Empty))
     {
         this.classname = this.GetWsClassName(Url);
     }
     else
     {
         this.classname = classname;
     }
     try
     {
         Stream stream = new WebClient().OpenRead(Url + "?WSDL");
         ServiceDescription serviceDescription = ServiceDescription.Read(stream);
         ServiceDescriptionImporter importer = new ServiceDescriptionImporter();
         importer.AddServiceDescription(serviceDescription, "", "");
         CodeNamespace namespace2 = new CodeNamespace([email protected]);
         stream.Close();
         CodeCompileUnit codeCompileUnit = new CodeCompileUnit();
         codeCompileUnit.Namespaces.Add(namespace2);
         importer.Import(namespace2, codeCompileUnit);
         ICodeCompiler compiler = new CSharpCodeProvider().CreateCompiler();
         CompilerParameters options = new CompilerParameters();
         options.GenerateExecutable = false;
         options.GenerateInMemory = true;
         options.ReferencedAssemblies.Add("System.dll");
         options.ReferencedAssemblies.Add("System.XML.dll");
         options.ReferencedAssemblies.Add("System.Web.Services.dll");
         options.ReferencedAssemblies.Add("System.Data.dll");
         CompilerResults results = compiler.CompileAssemblyFromDom(options, codeCompileUnit);
         if (results.Errors.HasErrors)
         {
             StringBuilder builder = new StringBuilder();
             foreach (CompilerError error in results.Errors)
             {
                 builder.Append(error.ToString());
                 builder.Append(Environment.NewLine);
             }
             throw new Exception(builder.ToString());
         }
         this.assembly = results.CompiledAssembly;
     }
     catch (Exception exception)
     {
         throw new Exception(exception.InnerException.Message, new Exception(exception.InnerException.StackTrace));
     }
 }
开发者ID:suizhikuo,项目名称:KYCMS,代码行数:47,代码来源:WebServiceHelper.cs


注:本文中的System.Web.Services.Description.ServiceDescriptionImporter.Import方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。