When I visit the page with the browser it is xml but when I request the url it is json. Is there something in mvc 4 api that makes it only output json to requests through the program or can I get xml back. Note: this is happening in a desktop application and a webpage so it has to be a setting of some sort and here was the error that the desktop gave me: Data at the root level is invalid. Line 1, position 1.
And yes I am loading the doc right and I checked the value by using json instead and it came back ok.
private void Plus_Click(object sender, EventArgs e)
{
string FValue = id.Text;
string SValue = id2.Text;
string ending;
string url = "http://localhost:56254/api/add?id=" + FValue + "&id2=" + SValue;
XmlDocument xdoc = new XmlDocument();
xdoc.Load(url);
XmlNode xNode = xdoc.SelectSingleNode("End");
ending = xNode.InnerText;
Answer.Text = ending;
}
This is my desktop application code. My code it gets the xml is right here:
namespace Calculator.Controllers
{
using Calculator.Models;
public class AddController : ApiController
{
public Calcs GetAddition(int id, int id2)
{
double end = id + id2;
Calcs[] calcs = new Calcs[] { new Calcs { FValue = id, SValue = id2, End = end } };
return calcs[0];
}
}
}
Here is Calcs:
namespace Calculator.Models
{
public class Calcs
{
public int FValue { get; set; }
public int SValue { get; set; }
public double End { get; set; }
}
}
Here is what the browser puts out:
<Calcs xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/Calculator.Models">
<End>60</End>
<FValue>55</FValue>
<SValue>5</SValue>
</Calcs>