I’m using the WebServiceHostFactory in my WCF services to avoid having to create a crapton of binding configuration in web.config.
However, I’d like to expose the services as XML/JSON and JSONP.
It does not look like I can extend WCF to add JSONP without resorting to a mountain of custom binding config.
So, for those who have done it, is it possible to have a restful WCF service that responds in XML/JSON/JSONP depending on the UriTemplate, without resorting to a ton of config wiring?
I think you should be able to do that pretty easily by having different methods in your service contract which have differing response formats:
and both methods could then call a common core function which does the actual computation / lookup of data or whatever you’re doing.
No big config war invovled for this, I’d say…. and it would solve at least two of your three points (XML and JSON).
JSONP isn’t natively supported in WCF – but as the article you referenced shows, you can fairly easily add this behavior. This does require some config wiring up, to enable this WCF extension, though. But it should be a one-time thing on your server, as far as I can see.
If you really can’t deal with this config setup, you could of course derive a custom
WebServiceHostFactoryWithJSONPSupportfrom theWebServiceHostFactoryused for the WCF REST services, and add the necessary extensions (like service behaviors etc.) to your host factory. The class is not sealed, so that should be simple enough (at least in theory 🙂 ).