admin管理员组

文章数量:1122832

I'm getting started with Reporting Services now and trying to create an automation to upload reports to the SSRS server.

The problem is i'm getting this error when trying to use the POST method:

{
    "error": {
        "code": "",
        "message": "Cannot create an abstract class."
    }
}

That's how the body of my requisition is:

{
"Name":"MyReport",
 "Type":"Report",
 "ParentFolder": {
        "Name": "Reports"
 },
 "Content":".rdl file bytes"

I'm trying to use it with c#, here's the code:

    private async Task<string> PostReportAsync(string jsonPayload)
    {
        using (HttpClientHandler handler = new HttpClientHandler { UseDefaultCredentials = true })

        using (HttpClient client = new HttpClient(handler))
        {
            client.DefaultRequestHeaders.Add("Accept", "application/json");

            HttpContent content = new StringContent(jsonPayload, Encoding.UTF8, "application/json");

            HttpResponseMessage response = await client.PostAsync(_apiUrl, content);
            string responseBody = await response.Content.ReadAsStringAsync();
            Console.WriteLine($"Response: {responseBody}");

            response.EnsureSuccessStatusCode();
            return await response.Content.ReadAsStringAsync();
        }
    }

In addition to that, I have this method:

  public async Task<string> UploadReportAsync(string reportName, string parentFolder, string reportFilePath)
  {
      try
      {
          byte[] fileBytes = await File.ReadAllBytesAsync(reportFilePath);
          string base64Content = Convert.ToBase64String(fileBytes);

          var payload = new
          {
              Name = reportName,
              Type = "Report",
              ParentFolder = parentFolder,
              Content = base64Content
          };

          string jsonPayload = JsonSerializer.Serialize(payload);

          return await PostReportAsync(jsonPayload);
      }
      catch (Exception ex)
      {
          throw new Exception("Erro ao fazer upload do relatório", ex);
      }
  }

Is there something wrong with the requisition body? I can't find anything on the API docs.

本文标签: cSQL Server Reporting Services API documentationStack Overflow