首页 > 解决方案 > Why a value of type Datetime becomes '01/01/0001 00:00:00' when received?

问题描述

I have very peculiar kind of an issue which is driving me nuts for the last so many months and i come back again and again in hope that I will fix it but cannot.

I have a web service written in c#. I pass it a date but it comes NULL. There are other data fields which are coming ok but this comes as '01/01/0001 00:00:00'.

private System.DateTime rEQ_STARTField;

[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, DataType="date")]
public System.DateTime REQ_START {
    get {
        return this.rEQ_STARTField;
    }
    set {
        this.rEQ_STARTField = value;
    }
}

When it is received by the method it becomes like '01/01/0001 00:00:00'.

Sending: (From client)

notif.REQ_START = dtRequestStartDate.Value.Date

REQ_START value is 3/4/2020.

I am using Forms.DateTimePicker at client's end but that's not the problem, no matter whatever I assign to it via any tool, it becomes '01/01/0001 00:00:00' once received.

Update:

Upon deserializing I found that the REQ_Start is not even getting transmitted. It's not even in the payload. Why?

标签: c#web-servicesdatetimec#-4.0

解决方案


推荐阅读