This is a migrated thread and some comments may be shown as answers.

solution, no problem: connect kendo widget to wcf webservice

0 Answers 31 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Henk Jelt
Top achievements
Rank 1
Henk Jelt asked on 03 Jul 2012, 10:52 AM
Hi 

I have been browsing the web for two days to find a solution for this issue, including this forum, and I could not find the solution.

I have built a WCF Restful Service based on an example, which returned a "valid json response", but not.

The first attempt was to serialize an object and then return it.
The result was a string that looked like json but which was in fact a string containing the json information:
"{jasonstring}"
This obviously did not work.
The way to detect it is to inspect the client-page in the browser, and look in the network tab, where the json output is printed.

The second attempt was to get rid of the outer-quotes.
In several discussions on the web it is recommended to serialize the object, and to stream it (defining the object as void) instead of returning it as a string. The quotes are gone, and json/validation sites do qualify the output as valid.
Nevertheless my Kendo grid did not populate.

The third attempt was to get rid of the streaming, based upon a discussion on stackoverflow (http://stackoverflow.com/questions/2086666/wcf-how-do-i-return-clean-json).
The advice in this discussion is to return the object as such, without any manipulation.
As long as the output of the webmethod is defined as json, ASP.NET will create a json string from the object,
And this worked.

example from the thread:

[WebInvoke(Method = "GET",
           
RequestFormat = WebMessageFormat.Json,
           
ResponseFormat = WebMessageFormat.Json,
           
UriTemplate = "players")]
public List<Person> GetPlayers()
{
   
List<Person> players = new List<Person>();
    players
.Add(new  Person { FirstName="Peyton", LastName="Manning", Age=35 } );
    players
.Add(new  Person { FirstName="Drew", LastName="Brees", Age=31 } );
    players
.Add(new  Person { FirstName="Brett", LastName="Favre", Age=58 } );

   
return players;
}


I hope that this thread will help all of you to find your solution earlier than I did.

KR

Henk Jelt




No answers yet. Maybe you can help?

Tags
General Discussions
Asked by
Henk Jelt
Top achievements
Rank 1
Share this question
or