tags:

views:

1214

answers:

3

What is the best way to create a JSON web service? We have another team that is using Java and they insist to having all communication done using JSON. I would prefer to use WCF rather than any 3rd party framework.

I found this blog: http://www.west-wind.com/weblog/posts/164419.aspx, and it suggests that the Microsoft implementation is flawed with M$ specific crap.

+1  A: 

If you use WCF and the 3.5 Framework, it couldn't be easier. When you mark your OperationContracts with the WebGet attribute, just set the ResponseFormat parameter to WebMessageFormat.Json. When the service is accessed RESTfully, it will return the data using the DataContractJsonSerializer.

It's really helpful to mark the POCOs that you want to JSON serialize as [DataContract] and to mark each serializable member as [DataMember]. Otherwise, you end up with funky JSON, as Rick pointed out in his blog post.

W. Kevin Hazzard
good example of all of this : http://stackoverflow.com/questions/2086666/wcf-how-do-i-return-clean-json/
Cheeso
A: 

I ended up using JayRock. Its fantastic piece of technology, just works. You don't get any NullReferenceExceptions like from this crap WCF if you don't configure it correctly.

Grzenio
A: 

I'm maintaining a open-source, cross-platform, high-performance web services framework that lets you trivially develop web services and have them automatically hosted on multiple endpoints without any configuration or code-gen required.

Out of the box it supports SOAP 1.1/1.2, XML, JSON and JSV endpoints. It also ships with the fastest JsonSerializer available for .NET.

For more info you can check out the live example website and google code project website.

mythz
Cheers, I will certainly give it a go!
Grzenio