Value when null does not show the value in xml

Asked

Viewed 608 times

0

I did that:

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

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

<Transacao i:nil="true"/>

You have to inhibit it and show the text?

REST web service with WCF.

2 answers

1

I had this same problem, the client that consumed WS treated xml as string in hand, they got lost when they didn’t have the full xml tag.

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

-1

A solution can be using Datanotations.

[DataMember(EmitDefaultValue = false)]

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

<Transacao i:nil="true"/>

XML appears with the notation "i:nil="true", which means that it is Serializing its class with the default values, try using something similar to:

    [DataContract(Name = "MinhaClasse", Namespace = "")]
    public class MinhaClasse
    {
        [DataMember(EmitDefaultValue = false)]
        public string Transacao { get; set; }
    }
  • Could you elaborate on your answer?

  • Here is the answer to this other topic: http://answall.com/questions/17297/returnr-apenas-completedfields-no-web-service The solution I recommended was used.

  • I’m not saying that your answer is incorrect, it’s just very "loose". I could detail where to use and how to use, this kind of thing?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.