using REST service from Asp.Net


Hello Everybody,

I am new in using jasper reort server.

I have created a report template and deploy it to jasper report server.

Now i want to call this report from my web application using REST API.


With the help of one forum i have written following code:

WebClient httpClient = new WebClient();
        httpClient.Credentials = new NetworkCredential("jasperadmin", "jasperadmin");
        httpClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
                // Build resourceDescriptor
        string requestXml;
        requestXml = "<resourceDescriptor name=\"testreport\" wsType=\"reportUnit\" uriString=\"/reports/samples/testreport\"";
        requestXml += " isNew=\"false\">";
        requestXml += "   <parameter name=\"Titel\">First Report</parameter>n";
        requestXml += "</resourceDescriptor>";
        // Send PUT, the requestAllResult contains the above <report>...
        string requestAllResult = httpClient.UploadString("http://localhost:8080/jasperserver/rest/resources/reports/samples/testre...", "PUT", requestXml);
        // Extract uuid and file
        System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
        XmlNode node = doc.DocumentElement.SelectSingleNode("uuid");
        string uuid = node.InnerText;
        //Build GET URL
        reportUrl += uuid;
        reportUrl += "?file=report";
        // Get report
        string report;
        report = httpClient.DownloadString(reportUrl);
After executing it , i am getting following error:

The remote server returned an error: (405) Method Not Allowed.

// Send PUT, the requestAllResult contains the above <report>...

Line 34: 
Line 35:         string requestAllResult = httpClient.UploadString("http://localhost:8080/jasperserver/rest/resources/reports/samples/testreport?RUN_OUTPUT_FORMAT=PDF", "PUT", requestXml);
Line 36: 
Line 37:         // Extract uuid and file

Please help to tell where i am doing wrong.


admin.vizexperts's picture
Joined: Feb 25 2014 - 2:53am
Last seen: 5 years 3 weeks ago

1 Answer:


You need to call the REPORTS method not the RESOURCE Method to execute the report. Check the Jasper Server Web Services Guide.

In RESTv1 that will look like this:


So in your case your code should look like this:

string requestAllResult = httpClient.UploadString("http://localhost:8080/jasperserver/rest/report/reports/samples/testreport?RUN_OUTPUT_FORMAT=PDF", "PUT", requestXml);

That is assuming your report URI is "/reports/samples/testreport". Also remember that to be able to issue REST requests you need to pass authentication to JRS (see REST Login Service).

Also consider using the REST_v2 APi that allows you to generate the report executions asynchronously.

marianol's picture
Joined: Sep 13 2011 - 8:04am
Last seen: 6 months 3 weeks ago

Thanks marianol, it is working.

admin.vizexperts - 5 years 1 month ago

Hi marianol,
It is working with rest api but not with rest_V2.
I have given the following url for rest_v2:
string requestAllResult = httpClient.UploadString("http://localhost:8080/jasperserver/rest_v2/reports/reports/samples/testr..., "PUT", requestXml);

It is showing following error: "The remote server returned an error: (404) Not Found."

Could you please correct me what I am doing wrong.

admin.vizexperts - 5 years 1 month ago

For REST V2, the output format is sent as an "extension" and request is a GET; see
So your call should be:
string requestAllResult = httpClient.UploadString("http://localhost:8080/jasperserver/rest_v2/reports/reports/samples/testr..., requestXml);

marianol - 5 years 1 month ago
show 4 more...

Hi Marianol,
Now i am using the following call:
string requestAllResult = httpClient.UploadString("http://localhost:8080/jasperserver/rest_v2/reports/reports/samples/testr..., requestXml);
but it is showing me "(400) Bad Request."

admin.vizexperts - 5 years 1 month ago

hello @Marianol
I have a report which has an input control `Report_id` . when I have to pass that ? when I a requesting the Xml `resourceDescriptor` or during uploading the xml .

junaid.khan_1 - 2 years 4 months ago

I agree to use rest v2 service. i success to call jaspert report via rest v2.
Please refer to below url

nagage - 2 years 3 months ago

Esta es otra opción con la que mande a ejecutar el WebService rest2, la cual retorna un byte, que se puede descargar, en el ejemplo se repite “reports”, porque de forma interna jasper maneja esa carpeta, y además yo tengo una carpeta que se llama igual, por lo que se tiene que repetir.

using System.Xml;
using System.Net;

public void Ejecuta(string path_reporte, string formatoDocumento, List<Paramertos> lista_parametros)
FormatoDocumento = formatoDocumento;
string url =http://localhost:8080/jasperserver/rest_v2/reports/reports/reporte_publi... + ".PDF" + "?j_username=jasperadmin&j_password=jasperadmin";

string parametros = "";

foreach (Paramertos objParametro in lista_parametros)
parametros = parametros + "&" + objParametro.Nombre + "=" + objParametro.Valor;

url = url + parametros;

WebClient myWebClient = new WebClient();
byte[] myDataBuffer = myWebClient.DownloadData(url);

if (myDataBuffer != null)
Gizmox.WebGUI.Common.Gateways.DownloadGateway download = new Gizmox.WebGUI.Common.Gateways.DownloadGateway(new System.IO.MemoryStream(myDataBuffer), "NombreDescarga.PDF");
catch (Exception ex)
throw ex;

mahero.xenix - 6 months 2 weeks ago