When i send the Javascript Date type to WCF Method as parameter, serialization problem occurs at the following. (Whereas they are both working with JSON).
DateTime content '2017-05-04T13:09:11.737Z' does not start with '\/Date(' and end with ')\/' as required for JSON.'.
What is the best way to solve this serialization issue? It seems it may solve with string manipulation but Is there any generic way for all WCF Methods that contains type of DateTime
? (Client side or Server side)
This is test Angular Http post
this.http.post(myTestDateUrl, JSON.stringify( {date : new Date()} ) , {headers: this.getHeaders()})
.subscribe(
data => {
console.log(data);
},
error => {
console.log(error);
}
);
private getHeaders() {
let headers = new Headers();
headers.append('Content-Type', 'application/json');
return headers;
}
This is WCF Test Method
[WebInvoke(
Method = "POST",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped)]
[OperationContract]
public Stream TestDate(DateTime date)
{
try
{
dynamic result = new { status = "OK"};
return Send(result);
}
catch (Exception ex)
{
dynamic result = new { status = "ERROR", error = ex.Message };
return Send(result);
}
}