Please see below, I replicated most of what was available on the jsreport-dotnet-client git
public class JsReportHelper
{
public TimeSpan? HttpClientTimeout { get; set; }
public IContractResolver ContractResolverForDataProperty { get; set; }
public async Task<Report> RenderAsync(string templateUri, string templateShortid, JObject jsonData)
{
JObject root = new JObject();
JObject template = new JObject
{
{ "shortid", templateShortid }
};
root.Add("template", template);
root.Add("data", jsonData);
string request = SerializerHelper.SerializeRenderRequest(templateShortid, jsonData.ToString(), ContractResolverForDataProperty);
CancellationToken ct = default(CancellationToken);
var client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", System.Convert.ToBase64String(
Encoding.UTF8.GetBytes(String.Format("{0}:{1}", Constants.JsReport_Username, Constants.JsReport_Password))));
if (HttpClientTimeout != null)
client.Timeout = HttpClientTimeout.Value;
var content = new StringContent(root.ToString(), Encoding.UTF8, "application/json");
var response = await client.PostAsync(templateUri, content, ct).ConfigureAwait(false);
if (response.StatusCode != HttpStatusCode.OK)
throw JsReportException.Create("Unable to render template. ", response);
response.EnsureSuccessStatusCode();
return await ReportFromResponse(response).ConfigureAwait(false);
}
private static async Task<Report> ReportFromResponse(HttpResponseMessage response)
{
var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
IDictionary<string, string> meta = new Dictionary<string, string>();
response.Headers.ToList().ForEach(h => meta[h.Key] = h.Value.FirstOrDefault());
response.Content.Headers.ToList().ForEach(h => meta[h.Key] = h.Value.FirstOrDefault());
return new ReportHttp()
{
Content = stream,
Response = response
};
}
}
This is how I invoke it
JsReportHelper jsService = new JsReportHelper();
//item.jsreport_url ("https://{host}/reporting/api/report")
//item.jsreport_shortid (js report template id)
//root (JObject)
var report = jsService.RenderAsync(item.jsreport_url, item.jsreport_shortid, root).Result;
I am not sure why but the error with the original code (see below) still persists.
ReportingService service = new ReportingService("https://{host}/reporting/api/report");
//or
ReportingService service = new ReportingService("https://{host}/reporting");