I struggle finding the solution for having an incoming POST request hit my service declaration unless the generic “application/xml” or “application/json” is set as Content-Type of the request:
Since we’re using custom MIME types, e.g. “application/vnd.company+xml”, this should really be the value of the Content-Type header. But clearly WCF cannot derive the request format from this. Does anyone know of a solution for this?
In short: I’d like
Content-Type: application/vnd.company+xml, and
Content-Type: application/vnd.company+json
to map the incoming POST request to XML and JSON respectively, but as of now, the service will only respond when I issue the POST request with
Content-Type: application/xml, or
Content-Type: application/json
Platform is .NET4 and WCF.
Use WCF Web API instead of WCF REST. One of the main advantages is that it gives you the flexibility to use any media type you want.
If you are really stuck with WCF REST in .net 4, then change your request parameter to stream type. That will allow you to POST whatever data you want. You will need to take care of the deserialization yourself.