Link to home
Start Free TrialLog in
Avatar of williamcampbell
williamcampbellFlag for United States of America

asked on

WCF XMLAttribute

I am returning some XML from WCF... using DataContract and DataMember

[DataContract]
public class Code
{
    [DataMember]
    String NuclearLaunchCode;

    [DataMember]
    String MessageToEnemy;
}

which will output

<Code>
   <NuclearLaunchCode>34526</NuclearLaunchCode>
   <MessageToEnemy>Have a Nice Day</MessageToEnemy>
</Code>

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

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

How do I modify My DataContract to output an Attribute?

I Tried adding

 [XmlAttribute("language")]
String language;

But it didn't work .. any ideas?


Avatar of GiftsonDJohn
GiftsonDJohn
Flag of India image

Hi,

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

http://blogs.microsoft.co.il/blogs/carmelh/archive/2008/10/07/contract-serialization-vs-xml-serialization.aspx
ASKER CERTIFIED SOLUTION
Avatar of williamcampbell
williamcampbell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of espadana
espadana

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.

Thanks
Avatar of williamcampbell

ASKER