admin.vizexperts Posted March 11, 2014 Share Posted March 11, 2014 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 asp.net 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/testreport?RUN_OUTPUT_FORMAT=PDF", "PUT", requestXml); // Extract uuid and file System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); doc.LoadXml(requestAllResult); XmlNode node = doc.DocumentElement.SelectSingleNode("uuid"); string uuid = node.InnerText; //Build GET URL string reportUrl = "http://localhost:8080/jasperserver/rest/resources/report/"; 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[/code]Please help to tell where i am doing wrong.Thanks Link to comment Share on other sites More sharing options...
Solution marianol Posted March 11, 2014 Solution Share Posted March 11, 2014 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:http://<host>:<port>/jasperserver[-pro]/rest/report/path/to/reportSo 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. Link to comment Share on other sites More sharing options...
admin.vizexperts Posted March 14, 2014 Author Share Posted March 14, 2014 Thanks marianol, it is working. Link to comment Share on other sites More sharing options...
admin.vizexperts Posted March 14, 2014 Author Share Posted March 14, 2014 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/testreport?RUN_OUTPUT_FORMAT=PDF", "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. Thanks Link to comment Share on other sites More sharing options...
marianol Posted March 14, 2014 Share Posted March 14, 2014 For REST V2, the output format is sent as an "extension" and request is a GET; see http://community.jaspersoft.com/documentation/jasperreports-server-web-services-guide/v550/running-report So your call should be: string requestAllResult = httpClient.UploadString("http://localhost:8080/jasperserver/rest_v2/reports/reports/samples/testreport.pdf","GET", requestXml); Link to comment Share on other sites More sharing options...
admin.vizexperts Posted March 15, 2014 Author Share Posted March 15, 2014 Hi Marianol, Now i am using the following call: string requestAllResult = httpClient.UploadString("http://localhost:8080/jasperserver/rest_v2/reports/reports/samples/testreport.pdf", requestXml); but it is showing me "(400) Bad Request." Link to comment Share on other sites More sharing options...
junaid.khan_1 Posted December 14, 2016 Share Posted December 14, 2016 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 . Link to comment Share on other sites More sharing options...
nagage Posted December 30, 2016 Share Posted December 30, 2016 I agree to use rest v2 service. i success to call jaspert report via rest v2. Please refer to below url https://nagagechou.blogspot.tw/2016/12/call-jasper-rest-v2-with-aspnet-mvc.html Link to comment Share on other sites More sharing options...
mahero.xenix Posted October 4, 2018 Share Posted October 4, 2018 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 lista_parametros) { try { FormatoDocumento = formatoDocumento; string url =http://localhost:8080/jasperserver/rest_v2/reports/reports/reporte_publicado" + ".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"); download.StartDownload(Ctrlform); } } catch (Exception ex) { throw ex; } } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now