【问题标题】:Reporting Service Web Service MVC Application报告服务 Web 服务 MVC 应用程序
【发布时间】:2017-09-06 17:05:13
【问题描述】:

我们正在构建一个 MVC 应用程序,我们需要渲染一些 SSRS 报告,因此我们正在尝试为此目的使用 Reporting Services Web 服务,寻找一些我找到的 SOAP API 文档this,所以我尝试复制该代码并编写我自己的控制器,但正如您所见,我没有返回任何 ActionResult,我不知道应该返回什么。

所以我的问题是,在 MVC 应用程序中使用 Reporting Service Web 服务的最佳方式是什么?如果 rs.Render 成功,我应该返回什么?

    public ActionResult soapReport(string path)
    {
        soapSSRS.ReportExecutionService rs = new soapSSRS.ReportExecutionService();
        rs.Url = "http://xxx.xxx.xxx.xx:xxxx/reportserver/ReportExecution2005.asmx";
        ;
        rs.Credentials = new System.Net.NetworkCredential(
                ConfigurationManager.AppSettings["ssrs_user"].ToString(), 
                ConfigurationManager.AppSettings["ssrs_pass"].ToString(), 
                ConfigurationManager.AppSettings["ssrs_domain"].ToString());

        // Render arguments
        byte[] result = null;
        string reportPath = "/MyReportFolder/MyReport";
        string format = "MHTML";
        string historyID = null;
        string devInfo = @"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>";

        // Prepare report parameter.
        soapSSRS.ParameterValue[] parameters = new soapSSRS.ParameterValue[3];
        parameters[0] = new soapSSRS.ParameterValue();
        parameters[0].Name = "token";
        parameters[0].Value = "XxXxXxXxXxXxXx";

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

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

        rs.ExecutionHeaderValue = execHeader;

        execInfo = rs.LoadReport(reportPath, historyID);

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

        try
        {
            result = rs.Render(format, devInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs);
            execInfo = rs.GetExecutionInfo();
        }
        catch (SoapException e)
        {
            Console.WriteLine(e.Detail.OuterXml);
        }
    }

【问题讨论】:

    标签: c# asp.net asp.net-mvc web-services reporting-services


    【解决方案1】:

    我这样做的方式是两步过程。

    第一步是生成报告 - 这就是您编写代码的目的。我在此步骤中所做的(在 AJAX 调用中启动该步骤)是在本地保存具有唯一名称的文件报告,然后返回 JsonResult,其中包含指示生成报告成功的代码、本地文件名和所需的远程文件名。

    然后这个 JsonResult 在 AJAX 调用的 .success 处理程序中被解析,另一个 Action 将被调用来下载文件。这是一个很好的例子:How To Create And Download File in ASP.Net MVC

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多