My apologies if this is a duplicate as there are many questions out there similar, but not quite what I'm looking for.
This is what I've written:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Xml.Serialization;
using DeptDataAccess;
namespace Basware_Web_Service.Controllers
{
public class DepartmentDataController : ApiController
{
public IEnumerable<Department> Get()
{
using (DeptDBEntities entities = new DeptDBEntities())
{
return entities.Departments.ToList();
}
}
This is what is generated:
<ArrayOfDepartment xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/DeptDataAccess">
<Department>
<Company>TEST_CO</Company>
<ID>1</ID>
<Text_1>0</Text_1>
<Text_2>Sample_1</Text_2>
</Department>
<Department>
<Company>TEST_CO</Company>
<ID>2</ID>
<Text_1>1</Text_1>
<Text_2>Sample_2</Text_2>
</Department>
<!--Additional Department elements omitted-->
</ArrayOfDepartment>
What I'm trying to do is replace the root element from ArrayOfDeparment to Document Element and the loop element from Department to Item.
I've tried adding XmlArrayItem, XmlRoot but keep getting errors and/or continuing to see ArrayOf*
Apologies for the delay in response... The data I was using was from a ADO.NET connection to my SQL Server DB. My attempts at trying to serialize an Array was never going to work so I ended up creating a "ParsedDeptData" Class to serialize and redefine the elements for delivery.
My parsed data class ended up looking like this:
I then adjusted my controller to be this:
Lesson learned was that, to my knowledge, you cannot serialize a method and need to make your adjustments further up stream.