Marco
Marco

Reputation: 2336

How can i set attributes with soap in WCF / .net

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

Answers (1)

Ladislav Mrnka
Ladislav Mrnka

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

Related Questions