XmlTextReader reader = new XmlTextReader(serviceUri + "?wsdl"); ServiceDescription serviceDescription = ServiceDescription.Read(reader); //创建客户端代理 ServiceDescriptionImporter importer = new ServiceDescriptionImporter(); importer.AddServiceDescription(serviceDescription, null, null); ////使用 CodeDom 编译客户端代理类 CodeNamespace namespace2 = new CodeNamespace("PlayerAuctions.WebServiceAgent.Dynamic"); CodeCompileUnit codeCompileUnit = new CodeCompileUnit(); codeCompileUnit.ReferencedAssemblies.Add("ConsoleApplication1"); codeCompileUnit.Namespaces.Add(namespace2); importer.Import(namespace2, codeCompileUnit); CSharpCodeProvider provider = new CSharpCodeProvider(); CompilerParameters options = new CompilerParameters(); //默认输出dll地址为C:\Users\sfu\AppData\Local\Temp 如果用户没有对此目录的操作权限,会引发filenotfound异常 CompilerResults results = provider.CompileAssemblyFromDom(options, new CodeCompileUnit[] { codeCompileUnit }); if (!results.Errors.HasErrors) { this.agentType = results.CompiledAssembly.GetTypes()[0]; this.agent = Activator.CreateInstance(this.agentType); }
results.PathToAssembly为null引发了filenotfound的异常。
已解决。
已解决?能把你的解决方案贴出来不?还没细看你的代码呢,问题就解决了~~~
XmlTextReader reader = new XmlTextReader(serviceUri + "?wsdl");
ServiceDescription serviceDescription = ServiceDescription.Read(reader);
ServiceDescriptionImporter importer = new ServiceDescriptionImporter();
importer.AddServiceDescription(serviceDescription, null, null);
CodeNamespace namespace2 = new CodeNamespace("PlayerAuctions.WebServiceAgent.Dynamic");
CodeCompileUnit codeCompileUnit = new CodeCompileUnit();
codeCompileUnit.Namespaces.Add(namespace2);
importer.Import(namespace2, codeCompileUnit);
CSharpCodeProvider provider = new CSharpCodeProvider();
CompilerParameters options = new CompilerParameters();
CompilerResults results = provider.CompileAssemblyFromDom(options, new CodeCompileUnit[] { codeCompileUnit });
this.agentType = results.CompiledAssembly.GetTypes()[0];
this.agent = Activator.CreateInstance(this.agentType);
@深谷&幽兰: 多谢!