ChartBlocks / php-ssrs

PHP library for connecting to SSRS over SOAP
MIT License
25 stars 22 forks source link

Cached WSDL file is the same for every request #28

Closed oranges13 closed 6 years ago

oranges13 commented 6 years ago

If you set the cache_wsdl_path because you don't have access to the temp dir on your web server, the cached WSDL is used even if it does not apply to the request you are making.

Example:

$options = array(
    'username' => 'myuser',
    'password' => 'mypass',
    'cache_wsdl_path' => 'my/writeable/dir/file.cache',
);

$ssrs = new \SSRS\Report("http://myserver/ReportServer", $options);

$ssrs->listChildren('/ReportsFolder'); // Works

$ssrs->getReport('/ReportsFolder/Example Report'); // Fails with error

You'll receieve the error Function ("LoadReport") is not a valid method for this service where LoadReport is whatever the subsequent action you are attempting to take is. This is because the WSDL has been cached and it is not refreshed between actions.

The same would occur if you redefined the object but use the same cache path between different requests.

$options = array(
    'username' => 'myuser',
    'password' => 'mypass',
    'cache_wsdl_path' => 'same/file.cache',
);

$ssrs = new \SSRS\Report("http://myserver/ReportServer", $options);

$ssrs->listChildren('/ReportsFolder'); // Works

$ssrs1 = new \SSRS\Report("http://myserver/ReportServer", $options);

$ssrs1->getReport('/ReportsFolder/Example Report'); // Fails with error

I was hoping to be able to define the connection once and reuse it for all the requests I had to make, rather than redefining the SSRS\Report object every time. Is there a way to have this thing automatically download new WSDL when the action has changed?

rb-cohen commented 6 years ago

Ah, I see the problem... if a path is not set we generate a cache file based on the WSDL URL. If we assume that the option cache_wsdl_path should be a directory and not a specific file, then append the cache file name to the end (as we do if the option is not set below), would that suffice?

In library/SSRS/Soap/NTLM.php we create a different cache file for each WSDL URL:

$options['cache_wsdl_path'] = $tmpDir . DIRECTORY_SEPARATOR . md5($wsdl) . '.wsdl';
oranges13 commented 6 years ago

Yeah, that would be great behavior! Unfortunately I don't have complete access to the server so I have to manually set the path to a writable dir, but that seems to want a specific file, not a directory.

rb-cohen commented 6 years ago

I've made this change and tagged v1.0.13, could you give it a go and let me know? cache_wsdl_path should be the base path now, with a file being generated for each endpoint.

oranges13 commented 6 years ago

Working great. I am able to define my connector globally in my controller. Thanks!