HttpResponseMessage can't serialize content
<p>I have empty .net rest api, which accepts only <code>XML</code>.
If the controller method returns the class I want to serialize directly, there are no problems. But I want to use response wrapper, so that all controller methods return <code>HttpResponseMessage</code>.</p>

<p>So this works:
FooController.cs:</p>

<pre><code>public FooResponse PostFoo(FooRequest foo)
{
  var fooVal = fooBll.GetFoo();
  return new FooResponse { Foo = fooVal;};
}
</code></pre>

<p>But this does not:
FooController.cs:</p>

<pre><code>public HttpResponseMessage PostFoo(FooRequest foo)
{
  var fooVal = fooBll.GetFoo();
  HttpResponseMesage response;
  response = fooBll.GetSuccessResponse(Url, new FooResponse {Foo = foovVal;});
  return response ;
}
</code></pre>

<p>ResponseBLL.cs:</p>

<pre><code>public HttpResponseMessage GetSuccessResponse(UrlHelper Url, object obj)
{
    this.requestMsg = HttpContext.Current.Items["MS_HttpRequestMessage"] as HttpRequestMessage;
    this.responseMsg = this.requestMsg.CreateResponse(HttpStatusCode.OK, obj);
    this.responseMsg.Headers.Location = HttpContext.Current.Request.Url;
    return this.responseMsg;
}
</code></pre>

<p>FooBLL inherits ResponseBLL, that's why I can call <code>fooBll.GetSuccessResponse</code>.</p>

<p>In WebApiConfig.cs I have:</p>

<pre><code>config.Formatters.XmlFormatter.UseXmlSerializer = true;
config.Formatters.Remove(config.Formatters.JsonFormatter);
</code></pre>

<p>Error I get is </p>

<blockquote>
  <p>The type FooResponse was not expected. Use the XmlInclude or
  SoapInclude attribute to specify types that are not known statically.</p>
</blockquote>

<p>Now I know there have been already a lot of questions with this issue and trust me, I have gone through all of them with no success. I have tried <code>[DataContract], [DataMember], [Serializable]</code> and <code>[XmlInclude]</code> attribute in all possible combinations I could think of. <code>[XmlInclude(typeof(FooResponse))]</code> on FooBLL class, <code>[XmlInclude(typeof(FooBLL))]</code> on ResponseBLL and so on.</p>

<p>I hope you can help me.</p>