I have a class called Customer
[Serializable]
[DataContract]
[XmlRoot(Namespace = "http://noatariff.com")]
public class Customer
{
public Customer()
{
DateTime now = DateTime.Now;
string datePart = now.ToString("yyyy-MM-dd");
string timePart = now.ToString("HH:mm:ss.fffzzz");
this.TimeReceived = String.Format("{0}T{1}", datePart, timePart);
}
[DataMember]
[XmlElement(Namespace = "http://noatariff.com")]
public string TimeReceived { get; set; }
}
Web api code
[HttpGet]
[Route("ping")]
public HttpResponseMessage GetCustomerTime()
{
Customer cust = new Customer();
HttpResponseMessage resp = Request.CreateResponse<Customer>(HttpStatusCode.OK, cust, new XmlMediaTypeFormatter(), "application/xml");
return resp;
}
When I access my method, I get the response as follows:
<Customer xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/PMPI_InterconnectService.Controllers">
<TimeReceived>2016-09-07T15:35:50.658-05:00</TimeReceived>
<head/>
</Customer>
I want to get the namespace information in response.
What I am missing?
<mcn:Customer xmlns:mcn="http://noatariff.com">
<mcn:TimeReceived>2016-09-07T15:46:46.845-05:00</mcn:TimeReceived>
</mcn:Customer>