In my WPF MVVM application I am getting Data from a restful WCF service in JSON format. I am de-serializing this data using JavaScriptSerializer. But this is not able to handle the null value if any. In this case I have to send some values instead of DBnull value which I do not want to send.
WCF service:
[OperationContract]
[WebInvoke
(
Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "ReportEmployee/All"
)
]
dcReportEmployee[] GetReportEmployee();
where dcReportEmployee is datacontract
[DataContract]
public class dcReportEmployee
{
[DataMember]
public string Name { get; set; }
[DataMember]
public Int32 Status { get; set; }
}
in WPF Application:
string sUrl = "LocalHostURL";
System.Net.WebRequest request = System.Net.HttpWebRequest.Create(sUrl);
request.Method = "GET";
request.UseDefaultCredentials = true;
request.ContentLength = 0;
System.Net.HttpWebResponse response = request.GetResponse() as System.Net.HttpWebResponse;
Stream objResponseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(objResponseStream);
string objResponseString = reader.ReadToEnd();
response.Close();
JavaScriptSerializer objJsonserialiser = new JavaScriptSerializer();
T[] arrResult = objJsonserialiser.Deserialize<T[]>(objResponseString);
here if objResponseString is containing any null value then its failing. I could have sent some replacement of null values but I do not want that.
Any thought on this ?