Click here to Skip to main content
16,017,922 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hii,

In the REST services I have created my [DataContract] looks like this :
C#
[DataContract]
public class Emp
{
[DataMember]
public Guid Eid {get;set;}
[DataMember]
public string Ename{get;set;}
[DataMember]
public DateTime CreatedDate{get;set;}

}


I am retrieving the results from database(SQL) and I am retrieving "Ename" value based on Eid.I wrote SQL query and its working fine.I am returing a list .Now I want to display it as JSON response .However I can view the XML response clearly like this :
C#
<Eid>00000000-0000-0000-0000-000000000000</Eid>
<Ename>John</Ename>
<CreatedDate>0001-01-01T00:00:00</CreatedDate>
When I decorate my OperationContract like this 
 [OperationContract]
        [WebInvoke(UriTemplate = "GetEName/?id={eid}", Method= "GET",ResponseFormat=WebMessageFormat.Json)]
        Emp GetName(Guid eid); 

and run the application then I am getting error:"[Fiddler] ReadResponse() failed: The server did not return a response for this request."

I guess this is only because browser is not taking default date to be 0001-01-01T00:00:00 in JSON response

How can I make this corrected and get the response when the returned date is 0001-01-01T00:00:00?What are the modifications I have to do in the code(DataContract) ?

Thanks in advance...
Posted

1 solution

hiii,
refer this link

if date is null then just replace it with blank space

WCF REST Service with JSON[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900