I am trying to provide a user interface that allows the user to add resource files to SSRS in an ASP.NET Core application. The user cannot manipulate the existing folder structure, only upload files. I can use the REST api to retrieve the folder structure, but when I go to post a new resource I get a 400 error response, Bad Request. Apparently this means my json is malformed but I can't figure out what's wrong. I wish the examples in https://app.swaggerhub.com/apis/microsoft-rs/SSRS/2.0#/Resources/AddResource were a little more robust.
Here is the class I use:
public class SSRSFile
{
public string Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string Path { get; set; }
public string Type { get; set; }
public bool Hidden { get; set; }
public Int64 Size { get; set; }
public string ModifiedBy { get; set; }
public string ModifiedDate { get; set; }
public string CreatedBy { get; set; }
public string CreatedDate { get; set; }
public string ParentFolderId { get; set; }
public string ContentType { get; set; }
public string Content { get; set; }
public bool IsFavorite { get; set; }
}
Here is the method I am using to post:
public async Task<IActionResult> ImportToSSRSAsync(
string Name
, string Path
, string ParentFolderId
, Int64 Size
, string ModifiedBy
, string ModifiedDate
, string Content
)
{
string SSRSUserName = HttpContext.Session.GetString("SSRSUserName");
string SSRSPassword = HttpContext.Session.GetString("SSRSPassword");
string SSRSURL = HttpContext.Session.GetString("SSRSURL");
var credentials = new NetworkCredential(SSRSUserName, SSRSPassword);
var client = new HttpClient(new HttpClientHandler() { Credentials = credentials });
SSRSFile newImportFile = new SSRSFile
{
Name = Name,
Path = Path,
Id = Guid.NewGuid().ToString(),
Description = "none",
Type = "Resource",
Hidden = false,
Size = 0,
ModifiedBy = ModifiedBy,
ModifiedDate = ModifiedDate,
CreatedBy = ModifiedBy,
CreatedDate = ModifiedDate,
ParentFolderId = ParentFolderId,
ContentType = "text/plain",
Content = Content,
IsFavorite = false
};
try
{
var importFile = System.Text.Json.JsonSerializer.Serialize(newImportFile);
HttpContent requestContent = new StringContent(importFile, Encoding.UTF8, "application/json");
var uri = SSRSURL + "/Resources";
var response = await client.PostAsync(uri, requestContent).ConfigureAwait(false);
response.EnsureSuccessStatusCode();
}
catch (Exception e)
{
throw new Exception("An error occurred importing to SSRS: " + e.Message + ". ||| ");
}
And this is the code that calls the method in my view:
var text1 = "abcdef";
await $.get("ABIReportsSSRS/ImportToSSRS", { Name: name, Path: fullpath, ParentFolderId: parentfolderid, Size: 0, ModifiedBy: "hlkra", ModifiedDate: "2017-04-13T15:51:04Z", Content: text1 }, function (data) {
location.href = "ABIReportsSSRS";
})
Some values are hardcoded for debugging purposes.
I know my uri is correct because it runs in a browser. I've checked and double-checked the data getting passed, and the names of the variables.
Any help would be appreciated.