Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This could be accomplished by using the ActionFilterAttribute. Action Filters basically intersects the request before or after the Action Result. So I just built a custom action filter attribute for POST Action Result. Here is what I did:</p> <pre><code>public class RestAPIAttribute : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { HttpContextBase httpContext = filterContext.HttpContext; if (!httpContext.IsPostNotification) { throw new InvalidOperationException("Only POST messages allowed on this resource"); } Stream httpBodyStream = httpContext.Request.InputStream; if (httpBodyStream.Length &gt; int.MaxValue) { throw new ArgumentException("HTTP InputStream too large."); } int streamLength = Convert.ToInt32(httpBodyStream.Length); byte[] byteArray = new byte[streamLength]; const int startAt = 0; /* * Copies the stream into a byte array */ httpBodyStream.Read(byteArray, startAt, streamLength); /* * Convert the byte array into a string */ StringBuilder sb = new StringBuilder(); for (int i = 0; i &lt; streamLength; i++) { sb.Append(Convert.ToChar(byteArray[i])); } string xmlBody = sb.ToString(); //Sends XML Data To Model so it could be available on the ActionResult base.OnActionExecuting(filterContext); } } </code></pre> <p>Then on the action result method on your controller you should do something like this:</p> <pre><code> [RestAPIAttribute] public ActionResult MyActionResult() { //Gets XML Data From Model and do whatever you want to do with it } </code></pre> <p>Hope this helps somebody else, if you think there are more elegant ways to do it, let me know.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload