Quantcast
Channel: User Lalit - Stack Overflow
Viewing all articles
Browse latest Browse all 34

Change REST Method Response XML Node name in MVC 4

$
0
0

We are building a REST Service using MVC4 and added method like:

    public IEnumerable<Contact> GetAllContacts()    {        return repository.GetAll();    }

The response of this method in XML generated as:

<ArrayOfContact xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><Contact><Id>1</Id><Name>Alice</Name><Email>alice@example.com</Email></Contact><Contact><Id>2</Id><Name>Bob</Name><Email>bob@example.com</Email></Contact><Contact><Id>3</Id><Name>Charles</Name><Email>charles@example.com</Email></Contact></ArrayOfContact>

I would like to change the tag <ArrayOfContact> to <Contacts>.I know if it would be a property of a class then we could add attributes to the property to change it.

But is it possible to change the Root Node of Response?


Viewing all articles
Browse latest Browse all 34

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>