I have created an ASP.NET Web API which finds the sum of two integers using an addition function from a dll file. When i run the application (http://localhost:52241/api/dlladdition/9/6
) i get results as "15"
. The result i want is something like { "result" : 15}
(JSON format). How do i achieve that? The JSON codes that i have included in my codes does not seem to work.
Here are my codes:
Addition.cs
using ClassLibraryDll;
public class Addition
{
static int num1;
static int num2;
int sum = MathClass.Add(num1, num2);
}
DllAdditionController.cs
public class Temp
{
public int num1 { get; set; }
public int num2 { get; set; }
public int sum { get; set; }
}
public class DllAdditionController : ApiController
{
private Addition addition = new Addition();
public int GET(int num1, int num2)
{
int result = ClassLibraryDll.MathClass.Add(num1, num2);
string json = JsonConvert.SerializeObject(result);
return (json);
}
}
Someone please help me. Thank you so much in advance.