I have written a RESTful web service using MVC4 Web API. One of the clients that is calling my web service is posting an XML body, but getting a JSON response.
I have learned that the client is not setting the header value of Content-type: application/xml or Accept: application/xml.
The client who is calling my web service is one of the largest companies in the world and refuses to add the required header values.
So my question is, how do I add the missing header values that the client is not sending so that my web service can return a response in XML?
Or how do I get my web service to response in XML with missing?
I have tried adding the following to the Global.asax.cs;
protected void Application_BeginRequest(object sender, EventArgs e)
{
if (HttpContext.Current.Request.HttpMethod == "POST"
&& HttpContext.Current.Request.CurrentExecutionFilePath.Contains("OrderInformation"))
{
HttpContext.Current.Request.Headers.Add("content-type", "application/xml");
HttpContext.Current.Request.Headers.Add("Accept", "application/xml");
}
}
But an exception is throw at runtime.
TIA
Matt