Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 277413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T01:04:33+00:00 2026-05-12T01:04:33+00:00

I am trying to provide a simple RESTful API to my ASP MVC project.

  • 0

I am trying to provide a simple RESTful API to my ASP MVC project. I will not have control of the clients of this API, they will be passing an XML via a POST method that will contain the information needed to perform some actions on the server side and provide back an XML with the result of the action. I don’t have problems sending back XMLs, the problem is receiving XML via a POST. I have seen some JSON examples, but since I will not control my clients (it could be even a telnet from my point of view) I don’t think JSON will work. Am I correct?

I have seen examples where clients simply construct the correct form format as part of the body of the request and then the ASP parse the message, and data is available as FormCollection (?param1=value1&param2=value2&,etc). However, I want to pass pure XML as part of the message body.

thanks for your help,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T01:04:33+00:00Added an answer on May 12, 2026 at 1:04 am

    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:

    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 > 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 < 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);
        }
    }
    

    Then on the action result method on your controller you should do something like this:

        [RestAPIAttribute]
        public ActionResult MyActionResult()
        {
            //Gets XML Data From Model and do whatever you want to do with it
        }
    

    Hope this helps somebody else, if you think there are more elegant ways to do it, let me know.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use some data from a PlanPlusOnline account. They only provide a
I'm trying to build a very simple location-based app and I have all of
I'm trying to provide a link to my company's website from a Windows Form.
I am trying to provide my own labelFunction for a CategoryAxis programatically but am
Trying to use an excpetion class which could provide location reference for XML parsing,
What functionality does the yield keyword in Python provide? For example, I'm trying to
I am trying to learn a little c++ and I have a silly question.
I am trying to make a simple searcher/highlighter and I am running into difficulties
I am trying to build a simple jQuery UI template and populate it with
I am trying to create a simple android application. I am new to Android

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.