Can't Add Data to the Report on ReportService Server

Posted by: dtujo on 5 June 2023, 6:43 am EST

    • Post Options:
    • Link

    Posted 5 June 2023, 6:43 am EST - Updated 5 June 2023, 6:51 am EST

    Created VS Studio Template for Web Assembly Report Viewer.

    I am passing an object through a POST request to the Report Service and Serializing it as JSON and trying to add it through the LocateDataSource. I have not been able to set data for the form. In the form I have the data schema set to the JSON schema of the data I am passing it.

    Here is the controller on the server:

    {
        [Route("/")]
        public class HomeController : Controller
        {
            [HttpPost("report")]
            public ActionResult Report([FromBody] ReportModel myData)
            {
                var reportData = JsonSerializer.Serialize(myData);
                Console.WriteLine(reportData);
                PageReport page_report = new PageReport();
                page_report.Document.LocateDataSource += (sender, args) =>
                {
                    args.Data = myData;                
                };
                GrapeCity.ActiveReports.Document.PageDocument reportDocument = new GrapeCity.ActiveReports.Document.PageDocument(page_report);      
                return new JsonResult(reportDocument);
            }
        }
    }

    Here is the code on WASM:

    using var report = await http.PostAsJsonAsync("************************/report", dataModel);
    _currentReport = await report.Content.ReadFromJsonAsync<string>();
    Console.WriteLine(_currentReport);
    await _viewer.OpenReport(_currentReport);

    It breaks in the controller on LocateDataSource:

    Unhandled Exception:
    System.Text.Json.JsonException: 'S' is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0.
     ---> System.Text.Json.JsonReaderException: 'S' is an invalid start of a value. LineNumber: 0 | BytePositionInLine: 0.
       at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan`1 bytes)
       at System.Text.Json.Utf8JsonReader.ConsumeValue(Byte marker)
       at System.Text.Json.Utf8JsonReader.ReadFirstToken(Byte first)
       at System.Text.Json.Utf8JsonReader.ReadSingleSegment()
       at System.Text.Json.Utf8JsonReader.Read()
       at System.Text.Json.Serialization.JsonConverter.DoSingleValueReadWithReadAhead(Utf8JsonReader& reader, ReadStack& state)
       at System.Text.Json.Serialization.JsonConverter`1[[System.String, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
       --- End of inner exception stack trace ---
       at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, JsonReaderException ex)
       at System.Text.Json.Serialization.JsonConverter`1[[System.String, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
       at System.Text.Json.JsonSerializer.ReadCore[String](JsonConverter jsonConverter, Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
       at System.Text.Json.JsonSerializer.ReadCore[String](JsonReaderState& readerState, Boolean isFinalBlock, ReadOnlySpan`1 buffer, JsonSerializerOptions options, ReadStack& state, JsonConverter converterBase)
       at System.Text.Json.JsonSerializer.ContinueDeserialize[String](ReadBufferState& bufferState, JsonReaderState& jsonReaderState, ReadStack& readStack, JsonConverter converter, JsonSerializerOptions options)
       at System.Text.Json.JsonSerializer.<ReadAllAsync>d__65`1[[System.String, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
       at System.Net.Http.Json.HttpContentJsonExtensions.<ReadFromJsonAsyncCore>d__4`1[[System.String, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
       at BlazorViewerWebAssembly.Pages.Index.ViewerInitialized() in C:\Users\dtujo\source\repos\ReportTesting\ReportTesting\BlazorViewerWebAssembly\Pages\Index.razor:line 77
       at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_1(Object state)
       at System.Threading.QueueUserWorkItemCallbackDefaultContext.Execute()
       at System.Threading.ThreadPoolWorkQueue.Dispatch()
       at System.Threading.ThreadPool.Callback()

    Picture attached of the reports JSON settings.

  • Posted 6 June 2023, 7:52 pm EST

    Hi Daniel,

    We could observe you have created a support ticket with the same issue [CAS-40987-T7F7N0] we have responded to your query there.

    Please continue the thread there to avoid confusion.

    Thanks,

    Anand

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels