Reporting Services动态引用WebServices发布报表 WebClient web = new WebClient();
Reporting Services动态引用WebServices发布报表        web.Credentials 
= System.Net.CredentialCache.DefaultCredentials;
Reporting Services动态引用WebServices发布报表
Reporting Services动态引用WebServices发布报表        Stream stream 
= web.OpenRead("WebServices地址");
Reporting Services动态引用WebServices发布报表
Reporting Services动态引用WebServices发布报表        
// 2. 创建和格式化 WSDL 文档。
Reporting Services动态引用WebServices发布报表
        ServiceDescription description = ServiceDescription.Read(stream);
Reporting Services动态引用WebServices发布报表
Reporting Services动态引用WebServices发布报表        
// 3. 创建客户端代理代理类。
Reporting Services动态引用WebServices发布报表
        ServiceDescriptionImporter importer = new ServiceDescriptionImporter();
Reporting Services动态引用WebServices发布报表
Reporting Services动态引用WebServices发布报表        importer.ProtocolName 
= "Soap"// 指定访问协议。
Reporting Services动态引用WebServices发布报表
        importer.Style = ServiceDescriptionImportStyle.Client; // 生成客户端代理。
Reporting Services动态引用WebServices发布报表
        importer.CodeGenerationOptions = CodeGenerationOptions.GenerateProperties | CodeGenerationOptions.GenerateNewAsync;
Reporting Services动态引用WebServices发布报表
Reporting Services动态引用WebServices发布报表        importer.AddServiceDescription(description, 
nullnull); // 添加 WSDL 文档。
Reporting Services动态引用WebServices发布报表
Reporting Services动态引用WebServices发布报表        
// 4. 使用 CodeDom 编译客户端代理类。
Reporting Services动态引用WebServices发布报表
        CodeNamespace nmspace = new CodeNamespace(); // 为代理类添加命名空间,缺省为全局空间。
Reporting Services动态引用WebServices发布报表
        CodeCompileUnit unit = new CodeCompileUnit();
Reporting Services动态引用WebServices发布报表        unit.Namespaces.Add(nmspace);
Reporting Services动态引用WebServices发布报表
Reporting Services动态引用WebServices发布报表        ServiceDescriptionImportWarnings warning 
= importer.Import(nmspace, unit);
Reporting Services动态引用WebServices发布报表        CodeDomProvider provider 
= CodeDomProvider.CreateProvider("CSharp");
Reporting Services动态引用WebServices发布报表
Reporting Services动态引用WebServices发布报表        CompilerParameters parameter 
= new CompilerParameters();
Reporting Services动态引用WebServices发布报表        parameter.GenerateExecutable 
= false;
Reporting Services动态引用WebServices发布报表        parameter.GenerateInMemory 
= true;
Reporting Services动态引用WebServices发布报表        parameter.ReferencedAssemblies.Add(
"System.dll");
Reporting Services动态引用WebServices发布报表        parameter.ReferencedAssemblies.Add(
"System.XML.dll");
Reporting Services动态引用WebServices发布报表        parameter.ReferencedAssemblies.Add(
"System.Web.Services.dll");
Reporting Services动态引用WebServices发布报表        parameter.ReferencedAssemblies.Add(
"System.Data.dll");
Reporting Services动态引用WebServices发布报表
Reporting Services动态引用WebServices发布报表        CompilerResults result 
= provider.CompileAssemblyFromDom(parameter, unit);
Reporting Services动态引用WebServices发布报表
Reporting Services动态引用WebServices发布报表        
// 5. 使用 Reflection 调用 WebService。
Reporting Services动态引用WebServices发布报表
        if (!result.Errors.HasErrors)

相关文章: