A .NET 4.5.2 app and .NET 5 Web API

Rod Falanga 561 Reputation points
2021-05-02T15:51:31.163+00:00

Where I work, we're busy replacing very old software processes (mostly Excel spreadsheets, sometimes a Microsoft Access app) with newer technologies. However, we are using .NET 4.5.2 (I've no idea why we're not using anything newer.) I'm considering writing some WebAPIs using .NET 5. (Maybe even putting the WebAPIs into Azure Services, but let's do one thing at a time.) My concern is whether the interaction between the two. If I do write .NET 5 WebAPIs I'll use EF Core 5. Can I send DbSets generated by EF Core to a .NET 4.5.2 Windows app?

Can a Windows 4.5.2 app understand the JSON sent to it from a .NET 5 WebAPI? I know that JSON is JSON, it's the structure sent and received I'm not sure if that will work or not. Does one side expect the JSON to conform to a different schema than the other side?

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,188 questions
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,426 questions
0 comments No comments
{count} votes

Accepted answer
  1. AgaveJoe 26,136 Reputation points
    2021-05-02T17:08:24.847+00:00

    Can I send DbSets generated by EF Core to a .NET 4.5.2 Windows app?

    .NET 5 is not compatible with .NET 4.5.2

    Can a Windows 4.5.2 app understand the JSON sent to it from a .NET 5 WebAPI?

    Yes. JSON stands for JavaScript Object Notation and has a standard format that is platform agnostic.

    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Duane Arnold 3,216 Reputation points
    2021-05-02T23:04:02.763+00:00

    @Rod Falanga

    Can a Windows 4.5.2 app understand the JSON sent to it from a .NET 5 WebAPI? I know that JSON is JSON,

    Yes you can send data from the .NET Core 5 WebAPI as long as you are not sending EF Core 5 model objects, which should be left at the WebAPI and not sent.

    You would map the EF model object over to a DTO and send the DTO. DTO travels between layers, tiers and client/service and not the EF model object.

    https://en.wikipedia.org/wiki/Data_transfer_object#:~:text=In%20the%20field%20of%20programming,that%20carries%20data%20between%20processes.&text=In%20other%20words%2C%20DTOs%20are,transferring%20data%20over%20the%20wire.

    https://learn.microsoft.com/en-us/aspnet/web-api/overview/data/using-web-api-with-entity-framework/part-5

    https://www.codeproject.com/Articles/1050468/Data-Transfer-Object-Design-Pattern-in-Csharp

    The WebAPI client using HTTPClient is not in direct contact with the WebAPI service so the client-side program should not care what the WebAPI is using.

    You have two choices with using the DTO pattern and how it is used by the WebAPI client and WebAPI service.

    1) Make a .NET Standard classlib project and keep the DTO(s) there that is sharable by the client-side project using .NET Framework 4 and by the WebAPI project using .NET 5.

    2) You make the DTO(s) in the 4.5 project and make the DTO(s) in the .NET 5 project with each being standalone in their respective projects.

    Either why should work.

    example usage of the DTO pattern with WebAPI client-side the MVC project and ServiceLayer projects doing CRUD with the DAL sitting behind the WebAPI that is using EF. The DTO(s) are kept in the Entities classlib project.

    https://github.com/darnold924/PublishingCompany

    HTH

    1 person found this answer helpful.
    0 comments No comments

  2. Rod Falanga 561 Reputation points
    2021-05-02T19:21:41.687+00:00

    OK @MikeGebhard-9797, if I understand you correctly, I cannot get a DbSet using EF Core in a .NET 5 WebAPI, then send that in response to a request from a .NET 4.5.2 application. I could serialize the DbSet to JSON and send that back in response to a request from a .NET 4.5.2 app. That answers my question. I have a follow-up question, which I'll ask separately.

    0 comments No comments