1

So I have a wcf service that is using soap requests to return data. This data is returned in xml format. What I was wanting to do was add attributes to the returned xml for a certain class.

For example

public class CustomClass
{
   private string key = "testKey";
   private string value = "100";
}

Would be returned as

<CustomClass key="testKey">100</CustomClass>

I have been looking around but cant find a solid answer.

McSick
  • 116
  • 1
  • 1
  • 6

1 Answers1

1

You need to bypass the DataContractSerializer to do this. Either implement IXmlSerializable on CustomClass to control the serialization entirely yourself, or use XmlSerializerFormatAttribute on your service or operation contract to use the XmlSerializer which will respect XmlAttribute attributes on the properties of your classes.

See How can you control .NET DataContract serialization so it uses XML attributes instead of elements?

Community
  • 1
  • 1
Simon Taylor
  • 207
  • 1
  • 2
  • 6