【问题标题】:SSRS SDK For PHP : Not working from PHP 5.5适用于 PHP 的 SSRS SDK:不适用于 PHP 5.5
【发布时间】:2017-03-24 08:17:19
【问题描述】:

我正在使用 SSRS SDK For PHP,它多年来一直没有更新,令人惊讶的是 (08.04.2010)。 它在 PHP 5.4 (5.4.44) 下运行良好,但在 5.5+ (5.5.37, 5.6.28, 7.x) 下运行良好

错误是:

array ( )未能连接到报告服务 请确保 url (https://myHost:60004/ReportServer/) 和凭据是 正确!

在第 207 行抛出异常,因为 var $content 等于 FALSE(因此无法加载内容)。

PHP 5.4.44 完全没问题。

我找不到关于支持的 PHP 版本的“SSRS SDK For PHP”文档...

我没有使用任何框架,例如 Symfony2、CakePHP、Zend Framework,...除了 Bootstrap。

有没有人知道或已经解决了这个问题?

编辑

正如评论中所问,这是我的代码:

function buildSSRSReport($companyId)
    {
        require_once '../tools/SSRSReport/SSRSReport.php';

        try {
            // Create a connection to the SSRS Server
            $rs = new SSRSReport(new Credentials(SSRS_USER_ID, SSRS_PASSWORD), SSRS_REPORT_SERVER_URL);
            $sqlConnection = self::getSqlConnection();

            // Load the report and specify the params required for its execution
            $executionInfo = $rs->LoadReport2(self::getSSRSEnvironment(), NULL);
            $parameters = array();
            $parameters[0] = new ParameterValue();
            $parameters[0]->Name = "CompanyId";
            $parameters[0]->Value = $companyId;
            $rs->SetExecutionParameters2($parameters);

            // Require the Report to be rendered in HTML format
            $renderAsHTML = new RenderAsPDF();

            // Set the links in the reports to point to the php app
            //$renderAsHTML->ReplacementRoot = getPageURL();

            // Set the root path on the server for any image included in the report
            //$renderAsHTML->StreamRoot = './images/';

            // Execute the Report
            $result_html = $rs->Render2($renderAsHTML,
                PageCountModeEnum::$Actual,
                $Extension,
                $MimeType,
                $Encoding,
                $Warnings,
                $StreamIds);

            $pdfFileName = self::getCompanyAlias($sqlConnection, $companyId) . ".pdf";

            header('Content-Type: application/x-download');
            header('Content-Disposition: attachment; filename="' . $pdfFileName . '"');
            header('Cache-Control: private, max-age=0, must-revalidate');
            header('Pragma: public');

            return $result_html;
        } catch (SSRSReportException $serviceException) {
            echo $serviceException->GetErrorMessage();
        }

    }

    function getSSRSEnvironment()
    {
        return "/DEV/CompanyESGReportingServices-DEV/Main";
    }

    private function getSqlConnection()
    {
        require_once("../inc/eth_connexion.php");
        /* These 4 variables are contained within the eth_connexion.php file */
        $serverName = SQL_SERVERNAME;
        $userName = SQL_USERNAME;
        $dbName = SQL_DATABASENAME;
        $password = SQL_PASSWORD;

        // SQLSRV : Connection array used when calling SQL via sqlsrv_query
        $connectionInfo = array("Database"=> SQL_DATABASENAME,
            "UID"=> SQL_USERNAME,
            "PWD"=> SQL_PASSWORD,
            "ReturnDatesAsStrings" => true);

        $sqlConnection = sqlsrv_connect($serverName, $connectionInfo);
        if (!$sqlConnection) {
            die('Can't log to the database');
        }

        return $sqlConnection;
    }

这里是 SSRSReport 构造函数的源代码(原始来自 SSRS SDK For PHP):

public function SSRSReport($credentials, $url, $proxy = null)
{        
    $this->_BaseUrl = ($url[strlen($url) - 1] == '/')? $url : $url . '/';
    $executionServiceUrl = $this->_BaseUrl . self::ExecutionService;
    $managementServiceUrl = $this->_BaseUrl . self::ManagementService;

    $options = $credentials->getCredentails();
    $stream_conext_params = array( 'http' =>
                                     array('header' =>
                                      array($credentials->getBase64Auth())));
    if(isset($proxy))
    {
        $options = array_merge($options, $proxy->getProxy());
        $stream_conext_params['http']['proxy'] = 'tcp://' .
                                                    $proxy->getHost() .
                                                    ':' .
                                                    $proxy->getPort();
        if($proxy->getLogin() != null)
        {               
            $stream_conext_params['http']['header'][1] = $proxy->getBase64Auth();
        }            
    }

    /**
     * If the SoapClient call fails, we cannot catch exception or supress warning
     * since it throws php fatal exception.
     * http://bugs.php.net/bug.php?id=34657
     * So try to load the wsdl by
     * calling file_get_contents (with warning supressed i.e. using @ symbol
     * infront of the function call)
     * http://stackoverflow.com/questions/272361/how-can-i-handle-the-warning-of-filegetcontents-function-in-php
     */
    $context = stream_context_create($stream_conext_params);
    $content = @file_get_contents($executionServiceUrl, false, $context);
    if ($content === FALSE) // I'M GOING HERE WITH PHP 5.5+ 
    {
        throw new SSRSReportException("",
                    "Failed to connect to Reporting Service  <br/> Make sure " .
                    "that the url ($this->_BaseUrl) and credentials are correct!");
    }

    $this->_soapHandle_Exe =  new SoapClient ($executionServiceUrl, $options);
    $this->_soapHandle_Mgt =  new SoapClient ($managementServiceUrl, $options);
    $this->ClearRequest();
}

确切的错误信息是:

https://myPublicHostProvider:60004/ReportServer/ReportExecution2005.asmx?wsdl 授权:基本=数组(1){ ["http"]=> 数组(1) { ["header"]=> 数组(1) { [0]=> 字符串(57) “授权:基本=”}}} 无法连接到报告服务 确保 url (https://myPublicHostProvider:60004/ReportServer/) 和凭据正确!

【问题讨论】:

  • 有没有人使用这个 SDK 并且在使用更新的 PHP 版本(5.5+)时遇到同样的问题?
  • 是的,我在 PHP 7.1 上使用这个 SDK。您能否澄清一下您看到的确切错误消息,如果可能的话,请说明与 SSRS 连接相关的源代码。
  • 感谢您的消息,并告诉我此 SDK 可与 PHP 7.1 一起使用。我的目标是迁移到最新的 PHP 版本。我在上面编辑了我的帖子,添加了调用 SDK 的函数的源代码。我还添加了我收到的确切错误消息
  • 您是否在您的报表服务器上启用了基本身份验证?据我所知,与我的代码相比,您使用的代码没有太大区别。我将发布详细信息的答案。

标签: php reporting-services sdk ssrs-2014


【解决方案1】:

用于 PHP 配置指针的 SSRS SDK

  • 确保您的报表服务器实例可访问。通过访问 Web 门户或服务 URL 对其进行测试。

  • 提供您的凭据。如果您通过了身份验证,那么您使用的凭据就是有效的。

  • 之后,进入目录\Program Files\Microsoft SQL Server\&lt;INSTANCE_NAME&gt;\Reporting Services\ReportServer,查找名为rsreportserver.config的文件

  • 找到这个sn-p

    <Authentication>
    <AuthenticationTypes>
        <RSWindowsNTLM/>
    </AuthenticationTypes>
    <Authentication>
    
  • 在&lt;RSWindowsNTLM/&gt; 条目下方添加&lt;RSWindowsBasic/&gt;。

供您参考,这是我在配置期间用于测试我的实例的 sn-p。

require_once( 'SSRSReport\bin\SSRSReport.php' );

define( 'UID', 'DOMAIN\Username' );
define( 'PASWD', 'Password' );
define( 'SERVICE_URL', 'http://127.0.0.1/SERVICE_URL/' );

try {
    $ssrs_report = new SSRSReport( new Credentials( UID, PASWD ), SERVICE_URL );
    $ssrs_report->LoadReport2( '/test', NULL );
    $renderAsHTML = new RenderAsHTML();
    $result_html = $ssrs_report->Render2(
        $renderAsHTML,
        PageCountModeEnum::$Estimate,
        $Extension,
        $MimeType,
        $Encoding,
        $Warnings,
        $StreamIds
    );
    echo $result_html;  
} catch ( SSRSReportException $serviceException ) {
    echo $serviceException->GetErrorMessage();
}

它可以成功加载位于加载路径上的RDL。

【讨论】:

  • 感谢您的代码。它与我的基本相同,只是您使用 HTML(对我来说是 PDF)和 PageCountModeEnum::$Estimate(对我来说是 $Actual)呈现。我看到您使用的是 HTTP,它是否适用于 PHP 5.5+(在您的情况下为 7.1)下的 HTTPS?
  • 我能够设置一个 HTTPS 实例,但我还没有测试它。鉴于此,我认为它也应该适用于 HTTPS。
  • 好的,我也认为它应该工作,但这是我的事实:)。如果有一天你在 HTTPS 下测试它并且你可以让它工作,请告诉我。谢谢。最好的问候,
【解决方案2】:

感谢您的帮助 MiSAKACHi。它为我指明了正确的方向。实际上,我在我无权访问的托管服务提供商上使用远程专用服务器。但是&lt;RSWindowsBasic/&gt; 在那里,因为它可以使用 PHP 5.4 加载报告。在这个版本下一切都很好。

感谢您,我发现了问题:我使用的是 HTTPS,而使用 HTTPS 时它不起作用,而当我使用 HTTP 时它起作用! 我正在与我的托管服务提供商核实他们是否可以做些什么。

编辑 - 解决方案

我的托管服务提供商去年解决了这个问题(忘记在此处发布)。在它没有修复的那段时间里,我还在 PHP 5.4 下。 我粘贴他们的原始信息:

您描述的这些问题是因为安装的证书是自签名证书。由于安全风险,新的 Web 浏览器和 PHP 版本不接受这些证书。

我们已将证书更改为官方颁发的证书

【讨论】:

    【解决方案3】:

    我只是想补充一点,我在使用codeplex ssrsphp 时遇到了问题,因此我用谷歌搜索并找到了另一个运行良好的 sdk。我正在使用 php 7+。 Here 是链接,如果有任何与此相关的问题,我随时待命。

    【讨论】:

    猜你喜欢
    • 2013-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-11
    • 2021-03-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多