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 9205455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:57:14+00:00 2026-06-17T23:57:14+00:00

I have a web service that uses the WCF REST Template 40. The way

  • 0

I have a web service that uses the WCF REST Template 40. The way my data is set up, there are no [DataContract] or [DataMember] attributes on anything, it is just the class and its public properties. Example:

public class Permission : ServiceClass
{        
    public int       PermissionID          { get; set; }
    public string    PermissionName        { get; set; }
    public string    PermissionCode        { get; set; }
    public string    PermissionDescription { get; set; }
    public bool      IsActive              { get; set; }
    public DateTime? StartDate             { get; set; }
    public DateTime? EndDate               { get; set; }
    public int       SystemID              { get; set; }
}

This works fine except that if a property is null, e.g the two DateTime objects, the json still contains those values. I would like for them to be omitted. I have tried to add the [DataMember(EmitDefaultValue=false)] and [DataMember(IsRequired=true)] (i’m not using the default serializer when reading in, so I don’t think I need that anyway) and it doesn’t seem to work. Has anyone had any experience with this and know some kind of workaround?

  • 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-06-17T23:57:16+00:00Added an answer on June 17, 2026 at 11:57 pm

    [DataMember] attributes are only enforced if the class is also decorated with [DataContract]. You can do that, but once you go to the data contract route, then the serialization becomes an “opt-in” model: you’ll need to declare the other members with [DataMember] as well:

    [DataContract]
    public class Permission : ServiceClass
    {
        [DataMember]
        public int       PermissionID          { get; set; }
        [DataMember]
        public string    PermissionName        { get; set; }
        [DataMember]
        public string    PermissionCode        { get; set; }
        [DataMember]
        public string    PermissionDescription { get; set; }
        [DataMember]
        public bool      IsActive              { get; set; }
        [DataMember(EmitDefaultValue = false)]
        public DateTime? StartDate             { get; set; }
        [DataMember(EmitDefaultValue = false)]
        public DateTime? EndDate               { get; set; }
        [DataMember]
        public int       SystemID              { get; set; }
    }
    

    Also, since this contract is now part of the data contract model, your base type (ServiceClass) will likely have to be changed to use the data contract as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web application that uses ajax enabled wcf service Service.scv .... I
I have been tasked with securing a web service that uses WCF and offers
I have a WCF web service that uses ASP.NET session state. WCF sets a
I have made a REST Web service, that works with Visual Studios WCF Test
I have a web service that uses nhibernate, calls to the web service go
I have a simple web service that uses an oracle database. When I test
I have a Web Service and an Android application that uses this web service.
I'm currently writing a WCF web service that uses LINQ to SQL to fetch
I have a web application that uses WCF to communicate with the back-end DB.
I have an application which uses wcf web service and after successful login, i

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.