Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7164443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:04:35+00:00 2026-05-28T14:04:35+00:00

By default, WCF deserializes missing elements into default values like null, 0 or false.

  • 0

By default, WCF deserializes missing elements into default values like null, 0 or false. The problem with this approach is that if it’s a basic type like number 0 I’m not sure whether it means the real value sent by an external system or a default value generated by WCF.

So my question is: Is it possible to find out at run-time whether the default value means “I didn’t send anything”.

This is crucial because we can’t update and overwrite existing data in the database with the default values just because the external system didn’t send a particular element this time (data corruption).

Microsoft’s short answer is “It is up to the receiving endpoint to appropriately interpret a missing element.”

Data member default values
http://msdn.microsoft.com/en-us/library/aa347792.aspx

Can somebody please clarify what’s that supposed to mean?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T14:04:36+00:00Added an answer on May 28, 2026 at 2:04 pm

    If you define your data members as properties, you can use whether the setter was called or not to decide whether some value was sent. The code below shows one data contract which knows whether it deserialized its fields.

    public class Post_51ca1ead_2f0a_4912_a451_374daab0101b
    {
        [DataContract(Name = "Person", Namespace = "")]
        public class Person
        {
            string name;
            int age;
            bool nameWasSent;
            bool ageWasSent;
    
            [DataMember]
            public string Name
            {
                get
                {
                    return this.name;
                }
    
                set
                {
                    this.nameWasSent = true;
                    this.name = value;
                }
            }
    
            [DataMember]
            public int Age
            {
                get
                {
                    return this.age;
                }
    
                set
                {
                    this.ageWasSent = true;
                    this.age = value;
                }
            }
    
            [OnDeserializing]
            void OnDeserializing(StreamingContext ctx)
            {
                this.ageWasSent = false;
                this.nameWasSent = false;
            }
    
            public override string ToString()
            {
                return string.Format("Person[Name={0},Age={1}]",
                    nameWasSent ? name : "UNSPECIFIED",
                    ageWasSent ? age.ToString() : "UNSPECIFIED");
            }
        }
    
        public static void Test()
        {
            MemoryStream ms = new MemoryStream();
            DataContractSerializer dcs = new DataContractSerializer(typeof(Person));
            dcs.WriteObject(ms, new Person { Name = "John", Age = 30 });
            Console.WriteLine(Encoding.UTF8.GetString(ms.ToArray()));
    
            string noAge = "<Person><Name>John</Name></Person>";
            ms = new MemoryStream(Encoding.UTF8.GetBytes(noAge));
            object p = dcs.ReadObject(ms);
            Console.WriteLine("No age: {0}", p);
    
            string noName = "<Person><Age>45</Age></Person>";
            ms = new MemoryStream(Encoding.UTF8.GetBytes(noName));
            p = dcs.ReadObject(ms);
            Console.WriteLine("No name: {0}", p);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

WCF's netTCPBinding is secured by default. As I understand it this means that.. Callers
By default a IIS hosted WCF service can't use libraries that uses user scope
Downloaded the WCF REST Template from this location. The default response format is XML,
I have WCF Client initialized like this MyServiceClient client = new MyServiceClient(); so it
In a solution, I added a WCF Service Library. No problem with the default
Today I began toying with WCF. One thing I noticed is that, by default,
I'm using the new features of .NET 4 and WCF that generate a default
I have two WCF Web API Contracts. Before this, I was happy that I
I have a WCF client generated with Add Service Reference, problem is that the
I have a very simple WCF service that I would like to expose publicly.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.