Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1910
  • Last Modified:

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?


0
williamcampbell
Asked:
williamcampbell
  • 2
1 Solution
 
GiftsonDJohnCommented:
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
0
 
williamcampbellAuthor Commented:
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



0
 
espadanaCommented:
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
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now