question

ShreyashKarmali avatar image
0 Votes"
ShreyashKarmali asked ShreyashKarmali commented

WCF Data Service Date format issue during POST request

Hi All,

I am using a WCF Data service with Entity framework. This WCF service is directly linked with a DB entity and endpoints for this service are auto-generated based on the tables present within the DB. I have configured the service to be compatible with V3 version of OData protocol by adding the following line in the service.


 config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;

When I try to POST a data object having date field, I am passing the datetime in ISO format string from client to the server. eg. for date - "10-Aug-2021 10:21 AM IST" I will pass it as "2021-08-10T04:51:00.000Z" in ISO.
dataObject = {
"Created": "2021-08-10T04:51:00.000Z"
}

When I use V2, i.e. by passing the header "MaxDataServiceVersion" with value 2.0, data is being stored in proper format, i.e. it adds +5.30 to the date time and stored it as 2021-08-10T10:21:00.000 in the DB

But, when I request the same body by passing "3.0" for "MaxDataServiceVersion" header, date is being stored as "2021-08-10T04:51:00.000" in the table which is not proper.

Request you all please provide help if you can on this issue.


Thanks,
Shreyash

dotnet-csharpwindows-wcfdotnet-entity-framework
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @ShreyashKarmali-2847 ,
Is it possible to change the time? Add a time increment step to return the value to make it match. If that fails, look at the official documentation and see if there are other methods.

1 Vote 1 ·

Hi @JiayaoWuMSFT-8028 ,

Thanks for your response!

It is not possible to change the date format from the client side. We are passing ISO date from client to the server. eg. for date - "10-Aug-2021 10:21 AM IST" I will pass it as "2021-08-10T04:51:00.000Z" in ISO.

The issue is only when we use DataServiceProtocolVersion.V3 instead of DataServiceProtocolVersion.V2.


Thanks,
Shreyash

0 Votes 0 ·

Hi @ShreyashKarmali-2847 ,
Use DataServiceProtocolVersion.V2 before finding out what's wrong with DataServiceProtocolVersion.V3. Maybe DataServiceProtocolVersion.V3 has a bug in this area.

1 Vote 1 ·
Show more comments

0 Answers