Basically as somebody have replied you just have to say
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "data/{id}")]
public Person GetData(string id)
{
// lookup person with the requested id
return new Person()
{
Id = Convert.ToInt32(id),
Name = "Leo Messi"
};
}
vikramchowda...
Member
484 Points
216 Posts
How To retrieve Data In Json Format From WCF
Feb 16, 2012 09:41 AM|LINK
Hi,
I am Using WCF Service now i am getting the data in xml format, Instead of that i need to get the data in Json Format.
Sincerely,
Vikram
bakamaru
Member
128 Points
76 Posts
Re: How To retrieve Data In Json Format From WCF
Feb 16, 2012 09:48 AM|LINK
u need to add [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json)] to ur method like this
[OperationContract]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json)]
public string helloworld()
{
return " hellow world";
}
kushalrdalal
Contributor
7130 Points
1273 Posts
Re: How To retrieve Data In Json Format From WCF
Feb 16, 2012 12:31 PM|LINK
Check this link which have step by step tutorial.
http://www.codeproject.com/Articles/167159/How-to-create-a-JSON-WCF-RESTful-Service-in-60-sec
http://msdn.microsoft.com/en-us/magazine/dd315413.aspx
Basically as somebody have replied you just have to say
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "data/{id}")] public Person GetData(string id) { // lookup person with the requested id return new Person() { Id = Convert.ToInt32(id), Name = "Leo Messi" }; }My Blog
LinkedIn Profile