问题描述
大家好,通过这个调用webservice,调用方法名是没有问题的。但是调用重载的方法时,mi为空。求大神指点指点啊!弄了一天了!string@namespace="EnterpriseServerBase.WebService.DynamicWebCalling";if((classname==null)||(classname=="")){classname=WebServiceHelper.GetWsClassName(url);}try{//获取WSDLWebClientwc=newWebClient();Streamstream=wc.OpenRead(url+"?WSDL");ServiceDescriptionsd=ServiceDescription.Read(stream);//注意classname一定要赋值获取classname=sd.Services[0].Name;ServiceDescriptionImportersdi=newServiceDescriptionImporter();sdi.AddServiceDescription(sd,"","");CodeNamespacecn=newCodeNamespace(@namespace);//生成客户端代理类代码CodeCompileUnitccu=newCodeCompileUnit();ccu.Namespaces.Add(cn);sdi.Import(cn,ccu);CSharpCodeProvidericc=newCSharpCodeProvider();//设定编译参数CompilerParameterscplist=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");//编译代理类CompilerResultscr=icc.CompileAssemblyFromDom(cplist,ccu);if(true==cr.Errors.HasErrors){System.Text.StringBuildersb=newSystem.Text.StringBuilder();foreach(System.CodeDom.Compiler.CompilerErrorceincr.Errors){sb.Append(ce.ToString());sb.Append(System.Environment.NewLine);}thrownewException(sb.ToString());}//生成代理实例,并调用方法System.Reflection.Assemblyassembly=cr.CompiledAssembly;Typetype=assembly.GetType(@namespace+"."+classname,true,true);objectobj=Activator.CreateInstance(type);System.Reflection.MethodInfomi=type.GetMethod(methodname);returnmi.Invoke(obj,args);}catch(Exceptionex){thrownewException(ex.InnerException.Message,newException(ex.InnerException.StackTrace));//return"Error:WebService调用错误!"+ex.Message;}}
解决方案
解决方案二:
问题已经解决