Ravi Selvaraj
Ravi Selvaraj

Reputation: 547

ASP.NET Web API 2 XML Post request ignore XML namespace attribute

For WebAPI XML request can the XML namespace can be ignored while model binding.

I want all the below requests to be bind correctly to my OrderHeader object:

<OrderHeader xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <OrderDate>2015-07-20T15:00:00</OrderDate>
  <CustomerAccountNumber>TEST1</CustomerAccountNumber>
  <CustomerPONumber>TEST2</CustomerPONumber>
  <CustomerReferenceNumber />
</OrderHeader>

<OrderHeader>
  <OrderDate>2015-07-20T15:00:00</OrderDate>
  <CustomerAccountNumber>TEST1</CustomerAccountNumber>
  <CustomerPONumber>TEST2</CustomerPONumber>
  <CustomerReferenceNumber />
</OrderHeader>

<OrderHeader xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/TEST.Models.API">
  <OrderDate>2015-07-20T15:00:00</OrderDate>
  <CustomerAccountNumber>TEST1</CustomerAccountNumber>
  <CustomerPONumber>TEST2</CustomerPONumber>
  <CustomerReferenceNumber />
</OrderHeader>

Upvotes: 1

Views: 606

Answers (1)

Brandon Seydel
Brandon Seydel

Reputation: 91

config.Formatter.XmlFormatter will get you where you want to go. There u can ignore namespace using properties on the formatter.

Upvotes: 0

Related Questions