使用ReportService2010.asmx以编程方式从sharepoint导出SSRS报告

vik*_*hta 8 excel sharepoint reporting-services ssrs-2008

我必须以编程方式将ssrs报告导出到excel,添加服务引用

HTTP:/siteurl/_vti_bin/ReportServer/ReportService2010.asmx

HTTP:/siteurl/_vti_bin/ReportServer/ReportExecution2005.asmx

有人可以提供一个有效的博客

dja*_*azz 10

我这样做是为了我目前在VS 2012 .NET 4.5上的工作,用于报告PDF报告的自动化.

答:为了便于使用,每次编译自己的代理类比引用Web服务更容易,因为您可能忘记了服务名称.

从Visual Studio命令提示符:

    wsdl /language:CS /n:"Microsoft.SqlServer.ReportingServices2010" http://<Server Name>/reportserver/reportservice2010.asmx?wsdl
Run Code Online (Sandbox Code Playgroud)

参考:http://msdn.microsoft.com/en-us/library/ms155134 (v = sql.105).aspx(只有当你想获取信息并执行时才需要服务:ReportExecution2005和ReportService2010.如果你只想要让你只需要ReportExecution2005)

B.创建代理类后,将其放入库项目中以便重用IMHO.如果你有多个环境,可能需要构建一些包装类来编写和配置文件中的一些服务器.

C.编写一些引用库的代码并在C#中构建第一次报告:

    using System;
    using System.IO;
    using System.Web.Services.Protocols;
    using myNamespace.MyReferenceName;  // YOUR PROXY PROJECT 

    class Sample
    {
    static void Main(string[] args)
    {
        ReportExecutionService rs = new ReportExecutionService();
        rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
        rs.Url = "http://myserver/reportserver/ReportExecution2005.asmx";

        // Render arguments
        byte[] result = null;
        string reportPath = "/AdventureWorks Sample Reports/Employee Sales Summary";
        string format = "MHTML";
        string historyID = null;
        string devInfo = @"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>";

        // Prepare report parameter.
        ParameterValue[] parameters = new ParameterValue[3];
        parameters[0] = new ParameterValue();
        parameters[0].Name = "EmpID";
        parameters[0].Value = "288";
        parameters[1] = new ParameterValue();
        parameters[1].Name = "ReportMonth";
        parameters[1].Value = "6"; // June
        parameters[2] = new ParameterValue();
        parameters[2].Name = "ReportYear";
        parameters[2].Value = "2004";

        DataSourceCredentials[] credentials = null;
        string showHideToggle = null;
        string encoding;
        string mimeType;
        string extension;
        Warning[] warnings = null;
        ParameterValue[] reportHistoryParameters = null;
        string[] streamIDs = null;

        ExecutionInfo execInfo = new ExecutionInfo();
        ExecutionHeader execHeader = new ExecutionHeader();

        rs.ExecutionHeaderValue = execHeader;

        execInfo = rs.LoadReport(reportPath, historyID);

        rs.SetExecutionParameters(parameters, "en-us"); 
        String SessionId = rs.ExecutionHeaderValue.ExecutionID;

        Console.WriteLine("SessionID: {0}", rs.ExecutionHeaderValue.ExecutionID);


        try
        {
            result = rs.Render(format, devInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs);

            execInfo = rs.GetExecutionInfo();

            Console.WriteLine("Execution date and time: {0}", execInfo.ExecutionDateTime);


        }
        catch (SoapException e)
        {
            Console.WriteLine(e.Detail.OuterXml);
        }
        // Write the contents of the report to an MHTML file.
        try
        {
            FileStream stream = File.Create("report.mht", result.Length);
            Console.WriteLine("File created.");
            stream.Write(result, 0, result.Length);
            Console.WriteLine("Result written to the file.");
            stream.Close();
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
        }

    }
    }
Run Code Online (Sandbox Code Playgroud)

取自这里:http://msdn.microsoft.com/en-us/library/reportexecution2005.reportexecutionservice.render(v=sql.105).aspx

D.(可选):您可能希望在SSRS托管服务器上处理刷新WebService.默认情况下,它每12小时回收一次,从而使第一个报告在缓慢后呈现.//(服务器名)/的ReportServer:您可以简单地使每10小时左右,在HTTP的服务端点webcall刷新这些服务.我使用一个名为Visual Cron的工具,可以设置自动化任务,你也可以尝试更改SSRS服务配置,创建自己的保持活动服务等.基本上你只需要更改设置或者与它交谈以保持它打开了.