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 8723905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:43:20+00:00 2026-06-13T07:43:20+00:00

I have not been able to get model binding to work when doing a

  • 0

I have not been able to get model binding to work when doing a POST using XML data with ASP.NET Web API. JSON data works fine.

Using a brand new Web API project, here are my model classes:

public class Person
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
}

public class PostResponse
{
    public string ResponseText { get; set; }
}

Here is my post method in the controller:

    public PostResponse Post([FromBody]Person aPerson)
    {
        var responseObj = new PostResponse();
        if (aPerson == null)
        {
            responseObj.ResponseText = "aPerson is null";
            return responseObj;
        }

        if (aPerson.FirstName == null)
        {
            responseObj.ResponseText = "First Name is null";
            return responseObj;
        }

        responseObj.ResponseText = string.Format("The first name is {0}", aPerson.FirstName);
        return responseObj;
    }

I am able to run it successfully with JSON from Fiddler:

Request Headers:
User-Agent: Fiddler
Host: localhost:49188
Content-Type: application/json; charset=utf-8
Content-Length: 38

Request Body:
{“FirstName”:”Tom”,”LastName”:”Jones”}

Result:
{“ResponseText”:”The first name is Tom”}

When passing in XML, the Person object is not hydrated correctly:

Request Headers:
User-Agent: Fiddler
Host: localhost:49188
Content-Type: text/xml
Content-Length: 79

Request Body:
<Person>
    <FirstName>Tom</FirstName>
    <LastName>Jones</LastName>
</Person>

Result:
<ResponseText>aPerson is null</ResponseText>

From what I understand XML should work similar to JSON. Any suggestions on what I’m missing here?

Thanks,
Skip

  • 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-06-13T07:43:21+00:00Added an answer on June 13, 2026 at 7:43 am

    Add this in your WebApiConfig.cs:

    config.Formatters.XmlFormatter.UseXmlSerializer = true;
    

    This forced Web API to use XMLSerializer instead of DataContractSerializer and allows you to pass raw XML.

    Otherwise you have to pass fully qualify datacontract XML i.e.:

    <Person xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/Test.WebAPI.Controllers">
    <FirstName>a</FirstName>
    <LastName>b</LastName>
    </Person> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Following the standard instruction for using AES algorithm, I have not been able to
I have been using this as a reference, but not able to accomplish exactly
I have not been able to find any definitive answers to this question: Can
I have a simple problem that I have not been able to find an
I have another weird problem which I have not been able to solve in
I have searched around and have not been able to find a solution for
So this is something that I have not been able to find any documentation
I have no code to really display here, since I have not been able
I'm working with a Ruby project for school, and have sadly not been able
I have tried a lot but not been able to understand the steps involved

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.