Using Reporting Services GetReportParameters web method

Wednesday, April 28, 2004

A question today on how to get the valid values for a report parameter via the web service API when a query specifies the valid values. (Whew - clunky sentence).

To do this you can use the GetReportParameters web method. First, be wary of a small bug in the documentation where the order of parameters are incorrect. Not a big problem with intellisense, though.

Example:

ReportingService rService = new ReportingService();
rService.Credentials = 
            System.Net.CredentialCache.DefaultCredentials;
 
string historyID = null;
bool forRendering = true;
ParameterValue[] values = null;                                  
DataSourceCredentials[] credentials = null;
ReportParameter[] parameters;
 
parameters = rService.GetReportParameters
            (
                        "/Northwind Reports/Report2",
                        historyID,
                        forRendering,
                        values,
                        credentials                                           
            );

This will give you back an array of ReportParameter objects. If a ReportParameter object has a set of valid values defined by a query, reporting services will run the query and populate the ValidValues property with ValidValue objects (only when ForRendering == true). If we wanted to dump the valid values for parameter[0]:

foreach(ValidValue v in parameters[0].ValidValues)
{
    Console.WriteLine(v.Label + " " + v.Value);
}

Note, if you have hierarchical parameters, where, for example, the set of valid values for parameters[1] depends on the value selected for parameters[0], you’ll need to initialize the ParameterValue array to get the valid values for parameters[1]. If you are doing this all from scratch this may mean multiple calls to GetReportParameters.


Comments
Rajesh Jagadeesan Tuesday, July 13, 2004
Hello sir,
<br>
<br>I tried exactly the same code, but when i executed the application, it gives the following error.
<br>
<br>System.Web.Services.Protocols.SoapException: The permissions granted to user 'DPA32W126\ASPNET' are insufficient for performing this operation.
<br>
<br>How do i correct this problem?
<br>
<br>Thankx in advance,
<br>Regards,
<br>Rajesh Jagadeesan
Scott Allen Tuesday, July 13, 2004
Hi Rajesh,
<br>
<br>You'll need to setup impersonation or run the ASP.NET application under an account with permissions to the report server (is it the same machine?)
<br>
<br>Here are some additional articles to help:
<br>
<br>http://odetocode.com/Resources/110.aspx
<br>http://odetocode.com/Articles/95.aspx
<br>http://odetocode.com/Articles/123.aspx
<br>
Moosa Tuesday, April 26, 2005
Hi,
<br>
<br>I have been playing with Reporting Services for sometime now and it seems to work great so far. I am now trying to render these reports into a web application. I am using the web service to render them. However, when I try to pass my paramters, it gives an &quot;System.NullReferenceException: Object reference not set to an instance of an object.
<br>&quot; exception. The following is the code I am trying to use.
<br>
<br>ParameterValue[] parameters = new ParameterValue[3];
<br>parameters[0].Value = &quot;20055&quot;;
<br>parameters[1].Value = &quot;000047&quot;;
<br>parameters[2].Value = &quot;83&quot;;
<br>
<br>Can someone please help. It seems like I am not defining my paramters correctly.
<br>
<br>Regards.
Moosa Tuesday, April 26, 2005
Actually i got it fixed. it should be like this.
<br>
<br>ParameterValue p1 = new ParameterValue();
<br>p1.Name = &quot;&lt;parameter name&gt;&quot;;
<br>p1.Value = &quot;20055&quot;;
<br>
<br>ParameterValue p2 = new ParameterValue();
<br>p2.Name = &quot;&lt;parameter name&gt;&quot;;
<br>p2.Value = &quot;000047&quot;;
<br>
<br>ParameterValue p3 = new ParameterValue();
<br>p3.Name = &quot;&lt;parameter name&gt;&quot;;
<br>p3.Value = &quot;83&quot;;
<br>
<br>ParameterValue[] parameters = new ParameterValue[3];
<br>parameters[0] = p1;
<br>parameters[1] = p2;
<br>parameters[2] = p3;
Dalia Friday, April 21, 2006
I am getting Error The type or namespace name 'ReportParameter' could not be found (are you missing a using directive or an assembly reference?)

please help.
Scott Allen Friday, April 21, 2006
Dalia:
Do you have a using directive? Did you use "Add Web Reference" in Visual Studio?
Dali Friday, April 21, 2006
Yes, I did. Now I can assign the parameters but can't display the report?
Dinesh Monday, November 20, 2006
Hi,

Thanks for this post but still i have some dobts..........
My problem is

I am using VS2003 and Sql server 2000 RS.

It a purely windows application. and i am using RE class file in stead of.....RS web services refrence.

My problem is .that i have listed all the reports on report server.

after selecting a report, it will show all the parameter names in first checklist box...and their corresponding values in another list box.



Now problem is that if suppose report has 4 parameters.....second parameter will be inabled after selecting first and same for third. i.e.their values depend upon first parameter to be passed.

first and 4 th will be independent.



my program is showing all the parameters in first check list and the value of first parameter in the second checklist.

now i want to select a value for first parameter then it will show related value for second parameter in the second list. but my program is showing first parameter value for all the parameters...so if u know then tell me that how can i pass first parameter value so that it will fetch the values for others.



Thanks And Regards

Dinesh
dinesht15@gmail.com
Comments are now closed.
by K. Scott Allen K.Scott Allen
My Pluralsight Courses
The Podcast!