1

I have following code in my controller

    [HttpGet]
    public IHttpActionResult Get_User_Info(long id)
    {
        user u = new user();
        List<user> lst = u.Get_userInfo(id);
        if (lst.Count==0)
        {
            return NotFound();
        }
        else
        return Ok(lst);
    }

and my user class is

public class user : NK.Objects._user
{

    public List<user> Get_userInfo(long userid)
    {
        address_city ac = new address_city();
        string sql = "select id ,username ,cgroup ,regDate ,name ,picadr ,tell ,caddresscity ,resadress ,email from " + tbl_name + " where id=@id";
        Q.dataaccesslayer.cmd.Parameters.Add("@id", System.Data.SqlDbType.BigInt).Value = userid;
        List<user> lst = Q.Execute_List<user>(sql, this, new Queries.Cmd_Parameters(), 10);
        lst.ForEach(t => t.resadress = ac.Get_City_Info(t.caddresscity) + " , " + t.resadress);
        return lst;
    }
}

user class inherits from following _ user class

public class _user
{
    public static string tbl_name = "tbl_user";
    public long id { get; set; }
    public string username { get; set; }
    public string password { get; set; }
    public long cgroup { get; set; }
    public string regDate { get; set; }
    public string name { get; set; }
    public string picadr { get; set; }
    public string tell { get; set; }
    public long caddresscity { get; set; }
    public string resadress { get; set; }
    public string email { get; set; }
}

the xml return is

<caddresscity xmlns="http://schemas.datacontract.org/2004/07/NK.Objects">1</caddresscity>
<cgroup xmlns="http://schemas.datacontract.org/2004/07/NK.Objects">1</cgroup>
<email xmlns="http://schemas.datacontract.org/2004/07/NK.Objects">1</email>
<id xmlns="http://schemas.datacontract.org/2004/07/NK.Objects">1</id>
<name xmlns="http://schemas.datacontract.org/2004/07/NK.Objects">1</name>

I think because of inheritance I am facing this problem and when I dont have inheritance it is working as expected.

How can I change the response to look as shown below:

<name>1</name>
Siva Gopal
  • 3,474
  • 1
  • 25
  • 22
amir jahany
  • 45
  • 1
  • 11
  • You mean, you don't want the xml response to have `xmlns=....` attributes on nodes? – Siva Gopal Feb 26 '17 at 18:50
  • yesssssssssssssssssssssssssss – amir jahany Feb 26 '17 at 20:14
  • @amirjahany - Looking at the various solutions in the [duplicate question](https://stackoverflow.com/questions/12590801/remove-namespace-in-xml-from-asp-net-web-api), if you don't want to mark your types with data contract attributes, or switch to `XmlSerializer`. [this solution](http://stackoverflow.com/a/38512000/3744182) of using the `[ContractNamespace]` assembly attribute should work for you. – dbc Feb 27 '17 at 20:35

0 Answers0