CHAPTER 9 RENDERING REPORTS FROM .NET APPLICATIONS
Note You can also use Basic authentication using rs.Credentials = new System.Net. Network-
Credential("username", "password", "domain");. The method you use depends on the security settings for
the report server virtual directory. By default, it’s configured to use Windows authentication.
Calling the Web Services GetItemParameters Method
The GetItemParameters method takes five parameters:
- Item: The full path name of the report/item.
- ForRendering: A Boolean value that indicates how the parameter values should be
used. You must set it to true to get a list of the possible values for each parameter. - HistorylD: The ID of the report history snapshot. You set it to null because you
aren’t running the report from a snapshot. - ParameterValues: The parameter values (ParameterValue[ ] objects) that can be
validated against the parameters of the report that are managed by the report
server. Set this to null for this example.Credentials: The data source credentials
(DataSourceCredential[] objects) that can be used to validate query parameters.
The GetItemParameters method returns an array of ItemParameter[] objects that contain the
parameters for the report. You use this information to render combo boxes that allow the users to select
the parameter values they want to use when running the report.
The following code sets up the variables you need to use and then calls the GetItemParameters
method to retrieve a list of parameters that the report expects, as shown in Listing 9-6.
Listing 9-6. Call to GetReportParameters
bool forRendering = true;
string historyID = null;
ParameterValue[] values = new ParameterValue[1];
DataSourceCredentials[] credentials = null;
ItemParameter[] parametersSSRS = null;
parametersSSRS = rs.GetItemParameters(report, historyID,
forRendering, values, credentials);
Once you have the list of parameters from SSRS 2012, you loop through them using the values to
create labels as you create your combo box for each parameter, like so:
foreach (ItemParameter rp in parametersSSRS)
Each ItemParameter object has a read-only property called ValidValues. You can use the
ValidValues property, which returns an array of ValidValue objects to populate the items in each combo
box, as shown in Listing 9-7.
Listing 9-7. Iterating Through the ValidValue Objects
if (rp.ValidValues != null) {
//Build list items