首页 新闻 赞助 找找看

创建代理动态调用webservice的时候,出现的一个问题。

0
悬赏园豆:20 [已关闭问题] 关闭于 2014-09-22 17:33
 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的异常。

深谷&幽兰的主页 深谷&幽兰 | 初学一级 | 园豆:131
提问于:2014-09-22 15:21
< >
分享
所有回答(2)
1

已解决。

深谷&幽兰 | 园豆:131 (初学一级) | 2014-09-22 15:27
0

已解决?能把你的解决方案贴出来不?还没细看你的代码呢,问题就解决了~~~

519740105 | 园豆:5810 (大侠五级) | 2014-09-22 17:23

 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);

支持(1) 反对(0) 深谷&幽兰 | 园豆:131 (初学一级) | 2014-09-22 17:33

@深谷&幽兰: 多谢!

支持(0) 反对(0) 519740105 | 园豆:5810 (大侠五级) | 2014-09-22 18:13
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册