Value when is null does not show value in xml

0

I did this:

if (lis.DT_TransacaoV == null)
                        pdv.Transacao = "Não Recebido";
                    else
                        pdv.Transacao = "Recebido";

I have in the object PDV a property called Transacao of type string. If it is different from null it does the homework, but if it comes null it throws that value:

<Transacao i:nil="true"/>

Can you inhibit this and display the text?

Web service REST with WCF.

    
asked by anonymous 28.05.2014 / 22:39

2 answers

1

I had this same problem, the client that consumed WS treated xml as a string in the hand, then lost when they did not have the full xml tag.

The solution was to throw a blank space when it was null.

    
20.09.2014 / 16:22
-1

A solution can be using DataNotations.

[DataMember(EmitDefaultValue = false)]

In this topic you have an answer that best exemplifies only that in his case, he wanted the null objects not to be serialized: Return only filled fields in web service , in this case when the string is null, the line will not appear in XML:

<Transacao i:nil="true"/>

The XML appears with the notation "i: nil=" true ", it means that it is serializing its class with the default values, try to use something like:

    [DataContract(Name = "MinhaClasse", Namespace = "")]
    public class MinhaClasse
    {
        [DataMember(EmitDefaultValue = false)]
        public string Transacao { get; set; }
    }
    
06.05.2015 / 15:23