Running report on JasperServer from C#

11,456

Jasper gives a Web Services API which you already have found, I suppose. For that being a Web Services using XML, it can be accessed through any language, like C# in this case, when you convert the service description (WSDL) to a service stub on that language.

On that given link there can be found Jasper Reports wsdl file locations and after having access to them your task is to create the stub, which is a code level access to the given XML interface. For Mono this can be done with a simple command line command according to this tutorial and the rest of the work is to use this code how ever you want to use it.

The exact command can be found through these two links with not much magic, but it is something as easy as one command running wsdl.exe with the given path (eg. http://localhost:8080/jasperserver/services/repository?wsdl) as argument and then compiling the result with a command similar to mcs /target:library SomeService.cs -r:System.Web.Services where you replace SomeService.cs with the name of the file that was the output of the previous command.

That's it!

Share:
11,456

Related videos on Youtube

FlappySocks
Author by

FlappySocks

Been programming since the early 80's, and doing it commercially since the early 90's. C#/Mono is my prefered language at the moment. Run my own internet hosting/networking startup company. Also make & sell ECU's for old BMW's. Live on southcoast of UK.

Updated on June 04, 2022

Comments

  • FlappySocks
    FlappySocks almost 2 years

    Jasper Reports is a superb open source alternative to Crystal Reports. It's great for single page PDF pages such as letters & invoices to multi-page reports. However it's not very .NET friendly, and getting C#/Mono to play nice with JasperServer has not been fruitful.

    Has anyone got any code samples of how to run a report on JasperServer from C#, and attach an XML dataset with the SOAP request? It needs to work on Mono, so Microsoft.Web.Services2 is out of the question.

    I had a go at trying to roll my own soap request. Jasper Server seems to accept it, but I cant seem to get any response back other than a server 500 error. I didn't get as far as attaching a MTOM attachment.

    var sb = new StringBuilder();
    
    sb.AppendLine("<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">");
    sb.AppendLine("<s:Body s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">");
    sb.AppendLine("<q1:runReport xmlns:q1=\"http://axis2.ws.jasperserver.jaspersoft.com\">");
    
    sb.AppendLine("<requestXmlString xsi:type=\"xsd:string\">");
    sb.AppendLine("<request operationName=\"runReport\" locale=\"en\">");
    sb.AppendLine("    <argument name=\"RUN_OUTPUT_FORMAT\">PDF</argument>");
    sb.AppendFormat("    <resourceDescriptor name=\"\" wsType=\"\" uriString=\"{0}\" isNew=\"false\">", "/JourneyReport");
    sb.AppendLine("      <label>null</label>");
    sb.AppendLine("      <parameter name=\"testparam\">1</parameter>");
    sb.AppendLine("    </resourceDescriptor>");
    sb.AppendLine("  </request>");
    sb.AppendLine("</requestXmlString>");
    sb.AppendLine("</q1:runReport>");
    sb.AppendLine("</s:Body></s:Envelope>");
    
    
    var webRequest = (HttpWebRequest)WebRequest.Create("http://localhost:8080/jasperserver/services/repository");
    webRequest.Credentials = new NetworkCredential("jasperadmin","jasperadmin");
    webRequest.PreAuthenticate = true;
    
    webRequest.Headers.Add("SOAPAction","");
    
    //Set HttpWebRequest properties
    byte[]  bytes = System.Text.Encoding.UTF8.GetBytes(sb.ToString());
    webRequest.Method = "POST";
    webRequest.ContentLength = bytes.Length;
    webRequest.ContentType = "text/xml; encoding='utf-8'";
    
    //Get Stream object 
    var objRequestStream = webRequest.GetRequestStream();
    objRequestStream.Write(bytes, 0, bytes.Length);
    objRequestStream.Close();
    
    var response = (HttpWebResponse)webRequest.GetResponse();
    
    • Alex K
      Alex K over 12 years
      May this post help you: stackoverflow.com/questions/4351511/…
    • FlappySocks
      FlappySocks over 12 years
      Thanks, but it wont work on Mono. I'll have to see if I can find a different SOAP library, or do it manually.
    • Yahia
      Yahia over 12 years
      is a commercial component an option ?
    • FlappySocks
      FlappySocks over 12 years
      Yes if the price is right. I did have a look at doing it using php as a go between, but I got into difficulties with that too. See stackoverflow.com/questions/8418261/…
    • torinfo
      torinfo about 12 years
      I've got REST working! See [Get report from jasperserver using REST webservice and asp.net C#][1] [1]: stackoverflow.com/questions/9623685/…
  • FlappySocks
    FlappySocks over 12 years
    How do you add the XML data source attachment? There is the XML Soap request, and an attachment which is the XML data for the report