Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to send XML through postman to a WEB API Controller but in Controller, the model is always null. I searched a lot and did all the changes in WebAPIConfig but still stuck in the same issue.<br/>
Note
This project contains other controllers also and they are working fine. <br/>

What I have tried:

WebApiConfig

<pre>
config.MapHttpAttributeRoutes();
            config.Formatters.XmlFormatter.UseXmlSerializer = true;
            config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}", new
            {
                id = RouteParameter.Optional
            });


Controller

C#
[HttpPost]
        public ResponseMessageResult CreatePayment([FromBody] Payment payment)
        {
        }


Model Class

C#
public class Payment
    {
        public PaymentHeaderList[] Header { set; get; }
        public PaymentLineList[] Lines { set; get; }
    }


PaymentHeaderList and PaymentLineList classes are also defined below Payment class


Postman Request

URL => http://localhost:6888/api/CreatePayment/payment




XML
POST /api/CreatePayment/payment HTTP/1.1
Host: localhost:6888
Content-Type: application/xml
cache-control: no-cache
Postman-Token: dbe183e9-0d6b-4ddf-b213-a1113bc19b6e

<Payment>
    <Header>
        <PaymentHeaderList>
            <AccountingDate>11111</AccountingDate>
            <JournalNameId>nnn</JournalNameId>
            <LegalEntity>yyy</LegalEntity>
            <Source>mmm</Source>
            <TaxIncluded>0</TaxIncluded>
            <TransDate>20190101</TransDate>
        </PaymentHeaderList>
    </Header>
    <Lines>
        <PaymentLineList>
            <AccountNumber></AccountNumber>
            <AccountType>Ledger</AccountType>
            <BusinessUnit>BusinessUnitTest</BusinessUnit>
            <Channel>REM</Channel>
            <CrAmount>222</CrAmount>
            <CurrencyCode>jjj</CurrencyCode>
            <Department>Payment</Department>
            <Description>aaa</Description>
            <DocumentNumber>1234555</DocumentNumber>
            <DrAmount>12000</DrAmount>
            <Employee>12333</Employee>
            <LineId>1.00</LineId>
            <Product>ProductTest</Product>
            <ProductCategory></ProductCategory>
            <Rate>1.0000</Rate>
            <TaxCode>No tax</TaxCode>
        </PaymentLineList>
    </Lines>
</Payment>


Where I am doing wrong. Please help
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900