williamcampbell
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</ NuclearLau nchCode>
<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</ NuclearLau nchCode>
<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?
[DataContract]
public class Code
{
[DataMember]
String NuclearLaunchCode;
[DataMember]
String MessageToEnemy;
}
which will output
<Code>
<NuclearLaunchCode>34526</
<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</
<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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
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