REST Data Source causing load failures on a grid

How's it going.
I'm trying out Radzen w/ Blazor. I have the latest Win/VS2019 updates.

I am failing to return the data in my grid:

I've made a WASM app in Radzen. I have two data sources, one is an Oracle production DB. Another is a rest service I created yesterday.

Here's the working output from my REST api (which is internet facing/available today w/ no security)

{
"ShowName":"Adobe Max ",
"ShowBeginDate":"2019-11-01T00:00:00",
"ShowEndDate":"NOV 08, 2019",
"ShowBeginDay":"FRIDAY ",
"ShowBegTime":"700",
"ShowEndDay":"FRIDAY ",
"ShowEndTime":"1130",
"SUBEGDate":"DEC 31, 1899",
"SUENDDate":"DEC 31, 1899",
"SUBEG_Day":"SUNDAY ",
"SBEDT":"0",
"SBETT":"0",
"SUENDDay":"SUNDAY ",
"SENDT":"0",
"SENTT":"0",
"TDBEGDate":"DEC 31, 1899",
"TDENDDate":"DEC 31, 1899",
"TDBegDay":"SUNDAY ",
"TBEDT":"0",
"TBETT":"0",
"TDEND_Day":"SUNDAY ",
"TEDDT":"0",
"TENTT":"0",
"PVBEGDate":"DEC 31, 1899",
"PVENDate":"DEC 31, 1899",
"PVBEGDay":"SUNDAY ",
"VBEDT":"0",
"VBETT":"0",
"VENDDay":"SUNDAY ",
"VENDT":"0",
"VENTT":"0",
"PRBEGDate":"DEC 31, 1899",
"PRENDDate":"DEC 31, 1899",
"PRBEGDay":"SUNDAY ",
"PBEDT":"0",
"PBETT":"0",
"PRENDDay":"SUNDAY ",
"PENDT":"0",
"PENTT":"0"
}

OData/Oracle is working great! I need to use the above rest though.
I can return json if I go to website dot com /annotator2020rest/api/abstract/2019/228619

2019 is a show year to filter by, and 228619 is a unique identifier for a show that recurs once a year.

The API/rest does not live in the Blazor project. It's on an IIS 08 dedicated server.

Here is how my DataSource is set up:

https://imgur.com/a/e29u3Ln
No auth. for now.

My resource settings are in that imgur album link I posted above (it's at the bottom)

I have Abstracts.items as an array of Abstract. Great, isn't that all I need to pull the json into a datagrid?

Then it finishes with my errors, and I go to my grid to set it up in the design view in Radzen. On the imgur link, its the first/top image w/ the load events.

OK well the preview got me excited. I selected the only possible choice under the Data drop down, GetAbstractResult.

The preview grabbed my column names and looks awesome.

The app first fails because
the having two '//' in a row in a URI is invalid. OK, I'll edit the endpoint even tho the example had this in.
I had two // in the HTTPs:// part. .NET didn't like that. OK, I just removed the https:\ and it compiled/ran.

Hey it's running! Data isn't coming through, though.

So I start debugging the client.
After entering the GetAbstract method in my AbstractService.cs file, the uri in this photo is way wrong.


Why is there a local host prefixed to my webserver.com/annota... ?
The Rest API does not and will not live in this app. It's on my company's web server.

Any idea how to even begin looking for the fix?

www.radzen dot com /documentation/rest/
I followed this to a tee (which errors if I don't fix the broken example for me)

Edit: Here's the error message that is caught on the razor.designer.cs file of the erroring page
imgur dot com /a/x6ZbSJh

Error text:
''<' is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0.'
Notice the "<'? What in the ??? is going on here?

Edit 2:
OK the baseUri which is fed into the request below is seemingly appending the navigationManager.BaseUri with the rest of the value I added into Radzen as the endpoint. BUT its missing the first letter. What the hell? I had to go into the data source, and add a space first. It's presumably doing a SubString(1, str.Length) or something and skipping the first character (0)? Maybe I should submit a bug report?

So it's doing localhost+mydomain/rest/endpoint to create this mess? Why??? I don't see a > or " character though. If I manually change this/hard code it and run it in IIS/VS2019 the app still builds, but will not load. What the hell. Is Blazor/Radzen too young at the moment?

Shouldn't the base uri be the literal endpoint since it's a REST service?

Here's the screen/error I get when trying to hard code the uri to the end point.
i.imgur dot com /djEbhWs.png

Edit 3:
MS Documentation excerpt on NavigatingManager.BaseUri:

Gets or sets the current base URI. The BaseUri is always represented as an absolute URI in string form with trailing slash. Typically this corresponds to the 'href' attribute on the document's element.

I didn't see an href anywhere but the " and < issues MUST be related surely!!!! Where to look? Getting closer :slight_smile:

Edit 4: Here is some more detail for my page's load event.

imgur dot com /a/2BuO1H4

Hey @DontDoThat21,

Thanks for reporting this! The issue will be fixed immediately and the fix will be released later today!

1 Like

Interesting, makes me a bit happier that I was pulling my hair out.
Are there any examples on how to use the REST data source w/ success today?

Thank you.

In the current official version of Radzen there is a problem with REST data source in WebAssembly Blazor applications. As I already replied the problem is already fixed and when we are ready with other fixes for this release we will publish new version.

@enchev Thank you Vladimir, apologies for not realizing your workflow. Awesome to hear that it's on the way though! Look forward to testing it :slight_smile:

I saw an update, I noticed only no-auth is an option now.

Still same issue w/ previous more than one slash issue described in detail above.

Can you post the generated code of the service?

using System;
using System.Collections.Generic;
using System.Web;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using Annotator2020.Models.Abstracts;

namespace Annotator2020
{
    public partial class AbstractsService
    {
        private readonly HttpClient httpClient;
        private readonly Uri baseUri;

        public AbstractsService()
        {
            this.httpClient = new HttpClient();
            this.baseUri = new Uri("REDACTED.REDACTED.com/annotator2020rest/api/**abstract/2019/248621**");        
        }

        partial void OnGetAbstract(HttpRequestMessage requestMessage);

        public async Task<AbstractsResponse> GetAbstract(int showYear = 2019, int showCode = 248621)
        {
            var uri = new Uri(baseUri, $"{showYear}/{showCode}");

            var message = new HttpRequestMessage(HttpMethod.Get, uri);

            OnGetAbstract(message);

            var response = await httpClient.SendAsync(message);

            response.EnsureSuccessStatusCode();

            using (var stream = await response.Content.ReadAsStreamAsync())
            {
                return await JsonSerializer.DeserializeAsync<AbstractsResponse>(stream, new JsonSerializerOptions
                {
                    PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
                    PropertyNameCaseInsensitive = true,
                });
            }
        }
    }
}

Notice the baseURI has 2019/XXXXX? Those are paramaters. I'm new to REST development, but shouldn't that URI stop after /abstract/ ?


BTW I get this error after adding a REST source.

The base URI is declared in Radzen data source screen. Where these parameters are defined? I don't see any double slash as well.

You were right I was using the default parameters in my endpoint. Fixed, but now when I have https:// in the endpoint like the documentation example, the application fails in the

program.cs

Even without the https:\ the same error occurs.

EDIT:
From VS2019 Debug output:

crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Invalid URI: The format of the URI could not be determined.
System.UriFormatException: Invalid URI: The format of the URI could not be determined.
** at (wrapper managed-to-native)** System.Reflection.RuntimeConstructorInfo.InternalInvoke(System.Reflection.RuntimeConstructorInfo,object,object[],System.Exception&)
at System.Reflection.RuntimeConstructorInfo.InternalInvoke (System.Object obj, System.Object[] parameters, System.Boolean wrapExceptions) <0x29856b0 + 0x0001e> in :0

The rest of the stack trace...
--- End of stack trace from previous location where exception was thrown ---

at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor (Microsoft.Extensions.DependencyInjection.ServiceLookup.ConstructorCallSite constructorCallSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext context) <0x2c520a0 + 0x00108> in :0
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2[TArgument,TResult].VisitCallSiteMain (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite callSite, TArgument argument) <0x2bdead8 + 0x000a8> in <filename unknown>:0 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite callSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext context, Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope serviceProviderEngine, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverLock lockType) <0x2c51450 + 0x000ce> in <filename unknown>:0 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite singletonCallSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext context) <0x30ffe60 + 0x00056> in <filename unknown>:0 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2[TArgument,TResult].VisitCallSite (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite callSite, TArgument argument) <0x2bde568 + 0x000c8> in :0

So...
why is neither
https://REDACTED.REDACTED.com/annotator2020rest/api/abstract or
REDACTED.REDACTED.com/annotator2020rest/api/abstract
valid as a URI? I can go into post man and receive a 200 status.. same with any browser.

Good lord lol, it was because the Client project was set as the default. The server project must be the default I guess when debugging.
image
For future reference, go into VS2019 and make sure Server is default.
Also, solution discussed here: Default Blazor App causes Browser error "crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component" ยท Issue #22364 ยท dotnet/aspnetcore ยท GitHub

My app is now running.. I'll try testing the DataGrid and REST functionality now.
^ Nevermind, it ran once after changing the Server to the default startup. It no longer want's to load and spits out the error:

Unhandled exception rendering component: Invalid URI: The format of the URI could not determined. System.UriFormatException: Invalid URI: The format of the URI could not be determined. at (wrapper managed-to-native) System.Reflection.RuntimeConstructorInfo.InternalInvoke(System.Reflection.RuntimeConstructorInfo,object,object,System.Exception&)

The only thing I really have in the app is my OData resource, a grid using that resouce and two no-data-connected drop downs...

The REST functionality still seems broken unless it's my user error.

Edit: Is Radzen constantly setting the client to the default project?

Edit: I am on
image
.NET Core 3.1.301

OK I think I've identified the steps to replicate the Radzen-generated error...
The baseURI = new URI (mentioned above thuroughly) must be https:// which is set in Radzen's data source menu. Great.

Manually changing that in visual studio doesn't do anything/still errors in the program.cs

So, to fix this scenario I had to go into Radzen, edit my data souce, change it to the uri WITHOUT the https:// first.

THEN, (at this point it still fails at program.cs like above) I must manually go into my AbstractService.cs and manually add a https://

If I edit any code in Radzen at this point, it regenerates the code and errors come back. Nice.

Radzen must be breaking something silently.

Edit:
By the way, once I get to the working-state described in this post, simply opening the App in Radzen doesn't break it. RUNNING the app (which seems to regen all code) breaks my app. Seems like the https:// is sticking somewhere.

This is in my Startup.cs
It changes according to the Radzen endpoint in the data source.
Notice its using MapODataRoute?

Is that appropriate for a REST route? Should I delete my Oracle data source?

For reference, that OracleTest route is valid and works as expected.

Edit: I created a brand new app, WASM Client side Blazor app and connected the same api w/ rest data source.
Here's the startup.cs it generated:

namespace GpjRents
{

public partial class Startup
{

    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    partial void OnConfigureServices(IServiceCollection services);

    partial void OnConfiguringServices(IServiceCollection services);

    public void ConfigureServices(IServiceCollection services)
    {
        OnConfiguringServices(services);

        services.AddHttpContextAccessor();
        services.AddCors(options =>
        {
            options.AddPolicy(
                "AllowAny",
                x =>
                {
                    x.AllowAnyHeader()
                    .AllowAnyMethod()
                    .SetIsOriginAllowed(isOriginAllowed: _ => true)
                    .AllowCredentials();
                });
        });

        services.AddRazorPages();
        OnConfigureServices(services);
    }

    partial void OnConfigure(IApplicationBuilder app, IWebHostEnvironment env);
    partial void OnConfiguring(IApplicationBuilder app, IWebHostEnvironment env);

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        OnConfiguring(app, env);
        if (env.IsDevelopment())
        {
            Microsoft.IdentityModel.Logging.IdentityModelEventSource.ShowPII = true;
            app.UseDeveloperExceptionPage();
            app.UseDatabaseErrorPage();
            app.UseWebAssemblyDebugging();
        }
        else
        {
            app.Use((ctx, next) =>
            {
                return next();
            });
        }
        app.UseHttpsRedirection();
        app.UseBlazorFrameworkFiles();
        app.UseStaticFiles();

        app.UseRouting();
        IServiceProvider provider = app.ApplicationServices.GetRequiredService<IServiceProvider>();
        app.UseCors("AllowAny");
        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllerRoute(
              name: "default",
              pattern: "{controller=Home}/{action=Index}/{id?}");

            endpoints.MapRazorPages();
            endpoints.MapControllers();
            endpoints.MapFallbackToFile("index.html");
        });

        OnConfigure(app, env);
    }
}

}

Does the REST functionality work at all?
http://jsonplaceholder.typicode.com/todos/

I tried making a new project. Set up the schema/data source correctly with the output from the above free api. It's a good one to test.

I tried to just feed it a default 1 as the ID.

crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Object reference not set to an instance of an object.

I wish I knew how to debug that. No idea.

I'm afraid that I cannot tell what's causing this exception. If you have Radzen subscription you can send us your app to info@radzen.com to debug it.

I am attaching a working application with the jsonplaceholder API.

TodosWASM.zip (4.4 KB)

1 Like

Thanks for the response. I only see .json files (no WASM Blazor .sln) however, I'll compare them to mine.

Radzen will generate everything (csproj, solution etc.) after you import the attached application in it.

Wonderful.. the example is working as expected.
I will try to learn what I am doing wrong.

OK so I was able to get that API working, the testing one.

I'm not understanding what I am doing wrong with my REST json output.
I keep erroring out, though the form seems to be auto generating the column names from the json.

meta.zip (3.9 KB)
I've uploaded my meta info.

Is something screwing up with arrays? I am only ever going to return one representation of an abstract ever with my current API. I am not returning an array from the JSON. Example input is included in my zip.

{
    "ShowName": "Adobe Max                               ",
    "ShowBeginDate": "2019-11-01T00:00:00",
    "ShowEndDate": "NOV 08, 2019",
    "ShowBeginDay": "FRIDAY   ",
    "ShowBegTime": "700",
    "ShowEndDay": "FRIDAY   ",
    "ShowEndTime": "1130",
    "SUBEGDate": "DEC 31, 1899",
    "SUENDDate": "DEC 31, 1899",
    "SUBEG_Day": "SUNDAY   ",
    "SBEDT": "0",
    "SBETT": "0",
    "SUENDDay": "SUNDAY   ",
    "SENDT": "0",
    "SENTT": "0",
    "TDBEGDate": "DEC 31, 1899",
    "TDENDDate": "DEC 31, 1899",
    "TDBegDay": "SUNDAY   ",
    "TBEDT": "0",
    "TBETT": "0",
    "TDEND_Day": "SUNDAY   ",
    "TEDDT": "0",
    "TENTT": "0",
    "PVBEGDate": "DEC 31, 1899",
    "PVENDate": "DEC 31, 1899",
    "PVBEGDay": "SUNDAY   ",
    "VBEDT": "0",
    "VBETT": "0",
    "VENDDay": "SUNDAY   ",
    "VENDT": "0",
    "VENTT": "0",
    "PRBEGDate": "DEC 31, 1899",
    "PRENDDate": "DEC 31, 1899",
    "PRBEGDay": "SUNDAY   ",
    "PBEDT": "0",
    "PBETT": "0",
    "PRENDDay": "SUNDAY   ",
    "PENDT": "0",
    "PENTT": "0"
}