Reputation: 2336
I am trying to make a soap server with the attribute OptIn in WCF / .net 4.0
This is my test code
[DataContract]
public class Relatie
{
[DataMember(IsRequired = false)]
public string Emailadres{ get; set; }
}
This will give a result without the OptIn, what must i add or change to specify this option?
<Relatie>
<EmailAdres OptIn="true">[email protected]</EmailAdres>
</Relatie>
Thanks in advance
Upvotes: 1
Views: 1093
Reputation: 364259
It is not possible when using DataContractSerializer
because it doesn't support XML attributes. You must use XML serializer instead:
public class Relatie
{
[XmlElement]
public string EmailAddress { get; set; }
[XmlAttribute]
public bool OptIn { get; set; }
}
And your operation contract, service contract or service implementation must be marked with [XmlSerializerFormat]
attribute.
Upvotes: 2