I have a REST service that has several clients consuming it that is set up to, as far as I can tell, only accept JSON when performing a POST/PUT (and only return JSON on all calls). The issue is that on the service /help page, it shows examples of JSON and XML both. Is there a way to remove all the extra XML garbage so as not to confuse users (since, again, the service only accepts JSON) and only display JSON examples on the /help page? Here's my Web.config:
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="false" defaultOutgoingResponseFormat="Json" />
</webHttpEndpoint>
</standardEndpoints>
And each of my GetGets/WebInvokes are defined w/ JSON as the formats, for example:
[WebInvoke(UriTemplate = "/sample", BodyStyle = WebMessageBodyStyle.Bare, Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
So, is there anything else I can do to let the service know that it's JSON only and remove the auto-gen XML junk cluttering up my /help pages?
Take your Microsoft.ApplicationServer.Http.HttpConfiguration config
and remove its XmlFormatter
(it has a JSON formatter and an XML formatter by default).
var config = new Microsoft.ApplicationServer.Http.HttpConfiguration();
config.Formatters.Remove(config.Formatters.XmlFormatter);
Now you can create an HttpServiceHostFactory
with this configuration, and use that to register routes.
//RouteTable is of type System.Web.Routing.RouteCollection
RouteTable.Add(new WebApiRoute(
"MyService",
new HttpServiceHostFactory { Configuration = config },
typeof(MyService)));
I don't have any credible source for you other than "it works for me."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With