How to dynamically assign property names for XmlOnlyMediaFormatter

Darryl Hoar 201 Reputation points
2026-08-26T15:38:37.4566667+00:00

I have been given an ASP.NET project to handle. It has been released and has worked fine.

I am not an ASP.NET developer but doing what I can. The issue:

The project is a webservice among other things. The solution (VS 2019) has 6 projects. One is the webservice.

The original developer created a class that has properties that have the same names as fields in a table in our sql server database. One user paid a company to create an app that through the web service pulls the data. This worked no problem. The fly in the ointment is that we changed the field names in the table as part of upgrades. This broke their custom app. They don't want to pay the developer to modify the app. I don't want to be bound by the customers external customizations. No, I can't say tough and force them.

The original developer used XmlOnlyMediaFormatter to return xml data for the webservice.

So, I was wondering if there was a way I can customize the xml tags returned from a webservice query with rewriting everything and changing the logic.

thanks for any guidance.

Developer technologies | C#
Developer technologies | 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.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 85,111 Reputation points
    2026-08-26T15:42:14.4+00:00

    you can override the field names in the class def:

        [XmlElement("FirstName")]
        public string First { get; set; } // Output tag will be <FirstName>
    
    

    if you really need dynamic, then your options are:

    • write your own xml formatter
    • create a new class(es) with the proper names and copy the data. the new class can be dynamically created via reflection.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.