C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,204 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I am trying to pass from a "POST" endpoint that contains data in XML format to my model class then save the same to my database.
It is possible for me to save the data when the XML is in the format below:
<NCBAPaymentNotificationRequest>
<User>USER</User>
<Password>pass</Password>
<HashVal>NzIwNGE3MzI5YmU5MTg3ZTUwZTQ1YmRjMjA0NDc2MjUyODQ2MmQ1ODIwZTIyYzNkNDk0NTBjNjUwZTgwYmM2Yw==</HashVal>
<TransType>999</TransType>
<TransID>FTC221024YAWQ</TransID>
<TransTime>2210241702</TransTime>
<TransAmount>1.00</TransAmount>
<AccountNr>6592460859</AccountNr>
<Narrative>Test</Narrative>
<PhoneNr>66666</PhoneNr>
<CustomerName>Customer 1</CustomerName>
<Status>SUCCESS</Status>
</NCBAPaymentNotificationRequest>
However, I want it saved when the XML is in the format below. It is at this point that I am facing issues:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<NCBAPaymentNotificationRequest>
<User>USER</User>
<Password>pass</Password>
<HashVal>NzIwNGE3MzI5YmU5MTg3ZTUwZTQ1YmRjMjA0NDc2MjUyODQ2MmQ1ODIwZTIyYzNkNDk0NTBjNjUwZTgwYmM2Yw==</HashVal>
<TransType>999</TransType>
<TransID>FTC221024YAWQ</TransID>
<TransTime>2210241702</TransTime>
<TransAmount>1.00</TransAmount>
<AccountNr>6592460859</AccountNr>
<Narrative>Test</Narrative>
<PhoneNr>66666</PhoneNr>
<CustomerName>Customer 1</CustomerName>
<Status>SUCCESS</Status>
</NCBAPaymentNotificationRequest>
</soapenv:Body>
</soapenv:Envelope>
Below is my Controller Code:
[Consumes("application/xml")]
[Produces("application/xml")]
[HttpPost]
public async Task<NCBAPaymentNotificationRequest> Post([FromBody] NCBAPaymentNotificationRequest value)
{
value.User = value.User;
value.Password = value.Password;
value.HashVal = value.HashVal;
value.TransType = value.TransType;
value.TransID = value.TransID;
value.TransTime = value.TransTime;
value.TransAmount = value.TransAmount;
value.AccountNr = value.AccountNr;
value.Narrative = value.Narrative;
value.PhoneNr = value.PhoneNr;
value.CustomerName = value.CustomerName;
value.Status = value.Status;
int createdId = mpesaRepository.Add(value);
if (createdId > 0)
{
value.ID = createdId;
}
return value;
}