Hello guys. i wanted to create a json web service. so i tried to use this code:
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json)]
DisCalResult[] DiscuntCalculaterJson(string fn, string ln);
public DisCalResult[] DiscuntCalculaterJson(string fn, string ln)
{
DisCalResult[] DCResult = null;
Calculater GetDis = new Calculater();
IPClass IP = new IPClass();
string iP = IP.GetIPAddress();
DCResult = GetDis.DisCal(fn, ln, iP);
return DCResult;
}
but it doesn't return the respond in json format. i foun another way i just use this one:
[OperationContract]
string DiscuntCalculaterJson(string fn, string ln);
public string DiscuntCalculaterJson(string fn, string ln)
{
DisCalResult[] DCResult = null;
Calculater GetDis = new Calculater();
IPClass IP = new IPClass();
string iP = IP.GetIPAddress();
DCResult = GetDis.DisCal(fn, ln, iP);
return new JavaScriptSerializer().Serialize(DCResult);
}
i have no idea what i have done but the second code worked.
whoud you please explain it to me and tell me what is the best way to create json web service?
Thank you.