If your service is used by Ajax clients (jQuery), you will get better performance using JSON.
Another recommendation; To get rid of the same domain policy, I recommend that you enable the crossDomainScriptAccessEnabled function:
<webHttpBinding> <binding name="myHttpBinding" crossDomainScriptAccessEnabled="true" /> </webHttpBinding>
Regarding DataContract; DataContract is not needed in your script.
Code example:
Your service:
[ServiceContract] [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class BlogService { [OperationContract] [WebGet(ResponseFormat = WebMessageFormat.Json)] public List<Article> GetBlogArticles() { return Article.GetDummyArticles.ToList(); } }
Article class (excerpt):
public class Article { public string Title { get; set; } public string Body { get; set; } public static IEnumerable<Article> GetDummyArticles() { yield return new Article { Title = "Article 1", Body = "sdlkfjsdlkfjskl" }; yield return new Article { Title = "Article 2", Body = "sfsfsdfd23434wfdfsfdfkfjskl" }; } }
For your scenario, I actually cannot find a reason to use any (third-party) library, since WCF4 already contains native JSON support with or without Padding.
source share