we have a some program that maximum support .NET 4.0 or 4.5 and program should connect to Net Core API,so We aren't use Newton Json and System.text.json due to system requirements,so do u have any advice Json convert that support .net framerowk 4 or 4.5
except NewtonSoft json
REST messages send to and received from Web API are NOT dependent on the framework version. If there were a dependency then Web API would be useless as only .NET client could send/receive messages.
Use any JSON serialization library you like in your client project.
Also, I think you'll be interested in learning REST (and Web API) fundamentals so you understand the basics.
hi ;
I have create a little demo that defined my problem
I have created 2 different VS project and one of them that running .Net 4.7 is working and the other not
I think I have experience Json serialize problem ,maybe I should add or configure middleware .Net core startup.cs or use another json component instead of NewTonSoft
// Class
public class Students
{
public int Id { get; set; }
public string Name { get; set; }
}
// Net Core Api 3.1
[HttpPost("{action}")]
public IActionResult TestApi(Students prm)
{
try
{
var data = prm.Id+"-"+prm.Name;
return Ok(data);
}
catch (Exception e)
{
var data = e.Message;
return Ok(data);
}
}
// This project using Net Framework 4.7.2 and its working
var api = new HttpClient();
var student = new Students
{
Id = 571632,
Name = "Test"
};
StringContent prm = new StringContent(JsonConvert.SerializeObject(student), Encoding.UTF8, "application/json");
var response = api.PostAsync("http://localhost:49972/api/WebApi/ApiTest", prm).Result;
var data = "";
if (response.StatusCode == HttpStatusCode.OK)
{
data = response.Content.ReadAsStringAsync().Result;
}
// This project using Net Framework 4.5 and its not working
var api = new HttpClient();
var student = new Students
{
Id = 571632,
Name = "Test"
};
StringContent prm = new StringContent(JsonConvert.SerializeObject(student), Encoding.UTF8, "application/json");
var response = api.PostAsync("http://localhost:49972/api/WebApi/ApiTest", prm).Result;
var data = "";
if (response.StatusCode == HttpStatusCode.OK)
{
data = response.Content.ReadAsStringAsync().Result;
}
I ran into a problem where XML was being sent to another application the was XML serialized from a custom class that eas being sent to clients that had a lower version of .NET from what the custom class was derived in. The clients didn't like it.
The solution was not to use the custom class and make the XML manually.
Maybe you need to do the same in making the json data manually without using a custom class and accessing the json gata manually on the client side without using the custom class.
If you find the post has answered your issue, then please mark post as 'answered'.
I ran into a problem where XML was being sent to another application the was XML serialized from a custom class that eas being sent to clients that had a lower version of .NET from what the custom class was derived in. The clients didn't like it.
The solution was not to use the custom class and make the XML manually.
Maybe you need to do the same in making the json data manually without using a custom class and accessing the json gata manually on the client side without using the custom class.
I ran into a problem where XML was being sent to another application the was XML serialized from a custom class that eas being sent to clients that had a lower version of .NET from what the custom class was derived in. The clients didn't like it.
The solution was not to use the custom class and make the XML manually.
Maybe you need to do the same in making the json data manually without using a custom class and accessing the json gata manually on the client side without using the custom class.
Member
4 Points
32 Posts
how to post complex data lower version of .NET
Jan 13, 2021 01:16 PM|alya14|LINK
hi ;
we have a some program that maximum support .NET 4.0 or 4.5 and program should connect to Net Core API,so We aren't use Newton Json and System.text.json due to system requirements,so do u have any advice Json convert that support .net framerowk 4 or 4.5 except NewtonSoft json
also I should send a class TO API as parameters
All-Star
52091 Points
23207 Posts
Re: how to post complex data lower version of .NET
Jan 13, 2021 02:58 PM|mgebhard|LINK
REST messages send to and received from Web API are NOT dependent on the framework version. If there were a dependency then Web API would be useless as only .NET client could send/receive messages.
Use any JSON serialization library you like in your client project.
Also, I think you'll be interested in learning REST (and Web API) fundamentals so you understand the basics.
All-Star
57834 Points
15485 Posts
Re: how to post complex data lower version of .NET
Jan 13, 2021 04:22 PM|bruce (sqlwork.com)|LINK
You can add xml support to asp.net core webapi. This is more compatible with ok’d asp.net
https://docs.microsoft.com/en-us/aspnet/core/web-api/advanced/formatting?view=aspnetcore-5.0
Member
4 Points
32 Posts
Re: how to post complex data lower version of .NET
Jan 13, 2021 05:41 PM|alya14|LINK
hi ;
I have create a little demo that defined my problem
I have created 2 different VS project and one of them that running .Net 4.7 is working and the other not
I think I have experience Json serialize problem ,maybe I should add or configure middleware .Net core startup.cs or use another json component instead of NewTonSoft
Contributor
4863 Points
4120 Posts
Re: how to post complex data lower version of .NET
23 hours, 36 minutes ago|DA924|LINK
I ran into a problem where XML was being sent to another application the was XML serialized from a custom class that eas being sent to clients that had a lower version of .NET from what the custom class was derived in. The clients didn't like it.
The solution was not to use the custom class and make the XML manually.
Maybe you need to do the same in making the json data manually without using a custom class and accessing the json gata manually on the client side without using the custom class.
Member
4 Points
32 Posts
Re: how to post complex data lower version of .NET
23 hours, 23 minutes ago|alya14|LINK
May you create a sample demo
All-Star
52091 Points
23207 Posts
Re: how to post complex data lower version of .NET
21 hours, 48 minutes ago|mgebhard|LINK
Your code has a few issues. See the following which comes directly form the official docs; https://docs.microsoft.com/en-us/aspnet/web-api/overview/advanced/calling-a-web-api-from-a-net-client
I tried both 4.5 and 4.7
Web API using System.Text.Json
Contributor
4863 Points
4120 Posts
Re: how to post complex data lower version of .NET
9 hours, 21 minutes ago|DA924|LINK
Json is just delimited string
How To Create JSON In C# (c-sharpcorner.com)
You simple make a string variable of the Json string and send the string variable.
You use a Parse to read the json on the client side.
Parsing JSON Object using JObject.Parse (newtonsoft.com)
You could use Linq-2-Json possibly on the client side.
Querying JSON with LINQ (newtonsoft.com)
But for sure, it can be done.