[Solved] Best practice for designing a WebAPI for exposing data in a SQL database interacting with C++ and C# applications

Hottemax Asks: Best practice for designing a WebAPI for exposing data in a SQL database interacting with C++ and C# applications
I am looking for general guidance or any relevant links for a complex project.

We are a small business that sells a construction materials testing software. The client is a Windows application with over 3 million lines of code, written almost entirely in legacy C++98. Business objects are persisted in a SQL database with hand-written serialization/deserialization in C++ without the use of external libraries.

Now we have developed a companion mobile application using Xamarin, soon to be .NET MAUI, which uses .NET standard C#. We have a ASP.NET Core WebAPI that also interacts with the same database as the C++ desktop application. It queries the database and returns json, where the format is documented via OpenAPI.

The challenge now is that there is no abstraction layer that provides an intermediate standard API for interacting with the database: when the user for example saves a complex BO from a dialog in the desktop application, there is no standard way to ensure that the same data is persisted as when we send a POST via the WebAPI, except for duplicating the C++ logic at the WebAPI server endpoint. For GET operations, we also need potentially non-trivial logic to resolve foreign keys etc. Obviously, this approach is not scalable to thousands of BOs.

With all of this preamble, our goal would be to design a common API to enable both the C++ and .NET “worlds” to share the same persistence layer logic.

This is quite challenging, and I am wondering if there are any experiences with how to approach this task.

Should the server be ASP.NET Core C# ? (it seems that the options for REST with C++ are quite limited) What technology should be taken to make allow both C++ and C# to access the API? Currently we use pInvoke to call more complex C++ persistence logic. … Any pointers, online resources or experiences are would be greatly appreciated! I would be happy to clarify and add more detail if the description is insufficient.

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.