I\'m trying to build a generic web service interface using WCF, to allow 3rd party developers to hook into our software. After much struggling and reading (this question helped
Actually <enableWebScript />
is not required for "pure" JSON support. The WebScriptEnablingBehavior is only required if you want to support ASP.NET AJAX. More often than not, if you're trying to work with standard script libraries, you don't want to enable this support for your services.
Instead what you want to do for your JSON endpoint is just use the WebHttpBehavior and set the DefaultOutgoingResponseFormat="JSON". The problem is, in .NET 3.5, you cannot control this setting through config because WebHttpElement does not expose these properties for configuration. To work around this in 3.5 have supplied an implementation for what I call the EnhancedWebHttpElement
here in this answer to another StackOverflow question.
Luckily Microsoft realized this shortcoming and enabled configuration of all the WebHttpBehavior
settings via the WebHttpElement in 4.0.
You have specified integer parameters in your operation. URI template does not work well with int parameters. Please change it to string , It will work.
I think you have to write your own QuerystringConverter to use int with URITemplate.
Drew's answer is spot on, but I think the question still stands. Is there a sane way of having JSON for AJAX () and the blessings of UriTemplate?
I think it is worth mentioning that JSON returned with is different than JSON generated with [WebGet(ResponseFormat=WebMessageFormat.Json)]. The former is wrapped around the the MS AJAX 'd' element e.g. {"d":[{...}]}.