tahirraza21 Ответов: 0

From body имеет значение null при отправке XML на контроллер webapi


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


Контроллер

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


класс моделей

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


PaymentHeaderList и PaymentLineList классы также определены ниже Платеж класс


Запрос Почтальона

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




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>


Где я поступаю неправильно. Пожалуйста помочь

0 Ответов