Hello
I'm using the WebDataSource component from Web Report Designer, and I want to receive data from our REST API.
On endpoints with no auth it works fine and the data gets loaded. But when I try to use 2-step auth (get token and pass it to api), I get a popup from web data source Wizard:
Error
Could not get preview.. An error has occurred. Object reference not set to an instance of an object.
And the debugger shows this:
WebDesigner Warning: 0 : Newtonsoft.Json.JsonReaderException: Error reading JObject from JsonReader. Path '', line 0, position 0. at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader, JsonLoadSettings settings) at Newtonsoft.Json.Linq.JObject.Parse(String json, JsonLoadSettings settings) at Telerik.Reporting.Processing.WebServiceDataSource.ErrorParsers.ErrorManager.ParseJson(String responseContent) WebDesigner Error: 0 : Object reference not set to an instance of an object. at Telerik.Reporting.Processing.WebServiceDataSource.WebServiceClient.SendCore(IWebServiceRequestSettings settings, AuthenticationHeaderValue authHeader, HttpClient httpClient, HttpClientHandler httpClientHandler) at Telerik.Reporting.Processing.WebServiceDataSource.WebServiceClient.GetTwoStepAuthorizationHeader(WebServiceTwoStepAuthentication processedAuth) at Telerik.Reporting.Processing.WebServiceDataSource.WebServiceClient.Request(WebServiceDataSource processedDS) at Telerik.Reporting.Processing.WebServiceDataSource.WebServiceDataProvider.GetRemoteRawData(WebServiceDataSource processedDS) at Telerik.Reporting.Processing.WebServiceDataSource.WebServiceDataProvider.get_RawData() at Telerik.Reporting.Processing.WebServiceDataSource.WebServiceSchemaAdapter.AddDataMeasures(SimpleDataModel model) at Telerik.Reporting.Processing.Data.SimpleDataProvider`1.GetSchemaCore() at Telerik.Reporting.Processing.Data.DataProvider`1.Telerik.Reporting.Processing.Data.IDataProvider.GetSchema() at Telerik.WebReportDesigner.Services.ConnectionsService.GetDataModel(DataSourceInfo dsi) WebDesigner Error: 0 : Object reference not set to an instance of an object. at Telerik.Reporting.Processing.WebServiceDataSource.WebServiceClient.SendCore(IWebServiceRequestSettings settings, AuthenticationHeaderValue authHeader, HttpClient httpClient, HttpClientHandler httpClientHandler) at Telerik.Reporting.Processing.WebServiceDataSource.WebServiceClient.GetTwoStepAuthorizationHeader(WebServiceTwoStepAuthentication processedAuth) at Telerik.Reporting.Processing.WebServiceDataSource.WebServiceClient.Request(WebServiceDataSource processedDS) at Telerik.Reporting.Processing.WebServiceDataSource.WebServiceDataProvider.GetRemoteRawData(WebServiceDataSource processedDS) at Telerik.Reporting.Processing.WebServiceDataSource.WebServiceDataProvider.get_RawData() at Telerik.Reporting.Processing.WebServiceDataSource.WebServiceSchemaAdapter.AddDataMeasures(SimpleDataModel model) at Telerik.Reporting.Processing.Data.SimpleDataProvider`1.GetSchemaCore() at Telerik.Reporting.Processing.Data.DataProvider`1.Telerik.Reporting.Processing.Data.IDataProvider.GetSchema() at Telerik.WebReportDesigner.Services.ConnectionsService.GetDataModel(DataSourceInfo dsi)
Auth URL is `https://localhost:5001/api/Account/Token2` and it should return plain text string with the token.
Request body is
{
"login": "admin",
"password": "foobar"
}
I click next-next in the Wizard and on the last step get the error above.
Why does not it work ??
The error message suggests that the issue occurs when the WebServiceDataSource attempts to make the POST request. When making a POST request, it is necessary to add a Content-Type request header with a value of application/json. This is likely the request for the token.
You may refer to step 5 of the solution in the Pass Parameter in WebServiceDataSource with Post Method - Telerik Reporting KB article for details on how to add the Content-Type request header.
Note that if the response is a simple plain-text string, the Token Path field should be left empty so that the entire login response is treated as the token by the component - WebServiceDataSource Component at a Glance - Telerik Reporting.
If that does not help, would it be possible to attach a copy of the report alongside an accessible Web API endpoint that we can use to test locally?
I look forward to hearing back from you.