Issue with sending XML to Web Api via http Post request

帅比萌擦擦* 提交于 2019-11-29 11:47:38

Final solution was to change the Post param type to XElement:

[Route("api/razorXmlRequest")]
public class RazorXmlRequestController : ApiController
{
    /// <summary>
    /// Raw Razor request XML 
    /// </summary>
    /// <returns>Razor reply message as text</returns>
    [HttpPost]
    public async Task<HttpResponseMessage> Post([FromBody]XElement xml)
    {
        HttpResponseMessage resp = new HttpResponseMessage(HttpStatusCode.OK);
        RazorSession cred = RzWebApi.Cred;
        string reply = await RzWebApi.RazorSrv.xmlRequests.Request(cred, xml);
        resp.Content = new StringContent(reply, System.Text.Encoding.UTF8, "application/xml");
        return resp;
    }
}

This worked straight-away without even providing the XmlFormatter as the gentlemen had suggested above (@TusharJ, thank you anyway for your input).

TusharJ

You can configure Web API to use XmlSerializer in your WebApiConfig.Register as follows;

config.Formatters.XmlFormatter.UseXmlSerializer = true;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!