WCF XMLAttribute

Posted on 2009-04-30
Last Modified: 2012-06-21
I am returning some XML from WCF... using DataContract and DataMember

public class Code
    String NuclearLaunchCode;

    String MessageToEnemy;

which will output

   <MessageToEnemy>Have a Nice Day</MessageToEnemy>

However I would like to have an attribute in the code Tag and the Nuclear tag

<Code PresidentOnly='true' >
   <MessageToEnemy language='Gaelic'>Have a Nice Day</MessageToEnemy>

How do I modify My DataContract to output an Attribute?

I Tried adding

String language;

But it didn't work .. any ideas?

Question by:williamcampbell
    LVL 14

    Expert Comment


    It is not possible using Contract Serialization. You have to convert your code to Xml Serialization.
    LVL 12

    Accepted Solution

    Thx Gift but I figured out how to solve the problem using DataContract serilaization

    I am going to write a blog about it as I've never seen it done before


    Expert Comment

    Hi williamcampbell,

    Can you tell me how you managed to fix this.  Ive been searching all over the net and still havent managed to find a way of doing it.

    LVL 12

    Author Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Suggested Solutions

    This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now