【问题标题】:SSRS Render reports using JAVA and SOAP Web ServiceSSRS 使用 JAVA 和 SOAP Web 服务呈现报告
【发布时间】:2016-09-20 14:58:40
【问题描述】:

我正在使用 SQL Server 开发 Java Web 应用程序和报告服务器,我想知道是否可以使用 SOAP Web 服务将报告从 SSRS 呈现到我的 Java 应用程序。

我正在使用SSRS-API 获取有关我的 SSRS 的信息,例如文件夹名称、报告名称……但我无法呈现我的报告或将其上传为 PDF 或其他扩展名。

有什么建议吗?

谢谢

编辑

我使用了上面提到的SSRS api(SSRS-API)的下载功能(downloadReport),这里是函数的代码:

public void downloadReport(final String path, final String filename) {
    final File file = new File(filename);
    final String physicalName = toPhysicalFileName(path);

    info("Downloading Report with symbolic name " + path + " to " + file);

    final byte[] data = _soap.getReportDefinition(physicalName);

    try (final FileOutputStream out = new FileOutputStream(file)) {
        out.write(data);
    } catch (final IOException ioe) {
        final String message = "Failed to download report with symbolic name " + path + " to " + file;
        LOG.warning(message);
        if (file.exists() && !file.delete()) {
            throw new IllegalStateException(message + " and failed to delete temporary file", ioe);
        } else {
            throw new IllegalStateException(message, ioe);

        }
    }
}

这是我使用的调用这个函数的函数:

public void downloadReport() {
    ssrs.downloadReport('Path/Report name', 'C:\\PATH\\TO\\A\\FOLDER\\REPORT.XML');
}

在给定的路径 (C:/PATH/TO/A/FOLDER/REPORT.XML) 我得到一个这样的 XML 文件:

<?xml version="1.0" encoding="utf-8"?>
<Report xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" xmlns:cl="http://schemas.microsoft.com/sqlserver/reporting/2010/01/componentdefinition" xmlns="http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition">
  <AutoRefresh>0</AutoRefresh>
  <DataSources>
    <DataSource Name="PercallAnalysisDW">
      <DataSourceReference>Entrepôt de données Percall Analysis</DataSourceReference>
      <rd:SecurityType>None</rd:SecurityType>
      <rd:DataSourceID>3a3e3aa4-c6d6-4b44-80f0-f18a9ecd2eac</rd:DataSourceID>
    </DataSource>
  </DataSources>
  <DataSets>
    <DataSet Name="DeliveryMarginCumuleDS">
      <SharedDataSet>
        <SharedDataSetReference>DeliveryMarginCumuleDS</SharedDataSetReference>
      </SharedDataSet>
      <Fields>
        <Field Name="Date">
          <DataField>Date</DataField>
          <rd:TypeName>System.String</rd:TypeName>
        </Field>
        <Field Name="Projet">
          <DataField>Projet</DataField>
          <rd:TypeName>System.String</rd:TypeName>
        </Field>
        <Field Name="LABOR_facturé">
          <DataField>LABOR_facturé</DataField>
          <rd:TypeName>System.Int32</rd:TypeName>
        </Field>
        <Field Name="TL_facturé">
          <DataField>TL_facturé</DataField>
          <rd:TypeName>System.Int32</rd:TypeName>
        </Field>
        <Field Name="Coût_total">
          <DataField>Coût_total</DataField>
          <rd:TypeName>System.Int32</rd:TypeName>
        </Field>
        <Field Name="DM">
          <DataField>DM</DataField>
          <rd:TypeName>System.Int32</rd:TypeName>
        </Field>
        <Field Name="Revenu">
          <Value>=Fields!LABOR_facturé.Value + Fields!TL_facturé.Value</Value>
        </Field>
      </Fields>
    </DataSet>
  </DataSets>
  <ReportSections>
    <ReportSection>
      <Body>
        <ReportItems>
          <Tablix Name="Tablix1">
            <TablixBody>
                ...

【问题讨论】:

    标签: java web-services sql-server-2008 soap reporting-services


    【解决方案1】:

    这是来自another answer 的文章,但请注意它来自 2005 年: JavaWorld。这是MSDN板上类似问题的答案:

    "但是,报表查看器控件仅在 .Net 中受支持 应用。所以不太可能将报告与java集成 基于前端,而无需启动新的浏览器页面。我的 建议是使用 URL 访问 Web 应用程序中的报告。 但是,如果您这样做,报告将在新浏览器中打开 页。”

    【讨论】:

    • 谢谢你的回复,我会看看这一切,我会给你一个反馈
    • 您好@RussellFox 我编辑了我的问题以添加我所做的事情,我现在可以获得报告的 XML 描述,我想知道您是否知道如何将此文件转换为PDF 或 EXCEL 等报告。
    【解决方案2】:

    我通过生成带有 URL 的报告解决了这个问题,这里是允许我生成报告的函数:

    public void downloadReportExcel(String path) {
        try {
            String url = "http://" + SSRS_IP + "/ReportServer?/" + path + "&rs:Format=Excel";
    
            FacesContext.getCurrentInstance().getExternalContext().redirect(url);
    
            return;
        } catch (IOException e) {
            throw new FacesException(e);
        }
    }
    

    该函数在参数中获取路径并使用 2 个参数将我重定向到服务器 url:

    • ?/path : 是要生成的报告的完整路径(从根文件夹开始)
    • rs:Format=Excel : 是生成的格式(这里我想把报表导出到Excel,但是可以取PDF,比如:&rs:Format=PDF)

    感谢@RussellFox 的帮助,我会尝试一下.NET 解决方案

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-24
      • 2019-01-08
      • 1970-01-01
      • 2013-06-06
      相关资源
      最近更新 更多