The back story is I have a web API that simply serves as a gateway to invoke external services. The reason for this is I don't want to expose the real business API to external services. So, in this gateway controller, it simply receives the information from the business API, calls external services and returns the response to the client, which is the business API.
In my gateway controller I have a POST action that takes a parameter of type HttpContent
, something like this:
[Route("api/test")]
public void Test(HttpContent content)
{
}
but the web API infrastructure doesn't know how to serialize and deserialize HttpContent
type. Is there a way to support my scenario?
Accessing the content of the request in any controller's handler is quite natural. Just call
Request.Content
inside. You can't have it as a parameter because it is not a mapping as an URI segment would nor a serialized content.Try something like:
BTW, assuming you are creating a REST API controller from what you said, don't forget to indicate the verb this handler is mapped to, either by using the
[Http<REST_verb>]
attribute inSystem.Web.Http
on the handler or by prefixing the handler name by the verb.Hope that helps!