Shrikant Sharma

Shrikant Sharma

  • NA
  • 85
  • 1.5k

Error in deserialising WCF json object C#

Sep 23 2016 6:09 AM

I have developed an application (C# MVC web and C# Desktop application) that communicates with database using WCF service.

It’s currently hosted at several locations, and is working fine. Except at one location, I’m facing issue with deserialisation of JSON object in one of the service method, only when calling through desktop application.

Error getting When deserialization : “There was an error deserializing the object of type System.Collections.Generic.List`1[Namespace.ModelClassName, Namespace, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]. Encountered unexpected character ':'.”

Deserialize Method Currently Using:

Try

var url = BaseServiceURL + "wsModel.svc/ ModelDynamicSearch " + "/" + ModelID.ToString() + "/" + SearchText.ToString() + "/" + SearchType.ToString();

var request = (HttpWebRequest)WebRequest.Create(url);

request.Method = "GET";

var response = (HttpWebResponse)request.GetResponse();

List<ModelName> lstVisitors = new List<ModelName>();

var t = new DataContractJsonSerializer(typeof(List<ModelName>));

using (var responseStream = response.GetResponseStream())

{

lstVisitors = (List<ModelName>)t.ReadObject(responseStream);

}

Catch

Error Getting

Finally

Service Contact:

[OperationContract]

[WebGet(UriTemplate = "ModelDynamicSearch/{ModelID}/{SearchText}/{SearchType}", ResponseFormat = WebMessageFormat.Json)]

List<ModelName> ModelDynamicSearch(string ModelID, string SearchText, string SearchType);

Model Definition:

public class ModelName

{

[DataMember]

public int ModelID { get; set; }

[DataMember]

public int ModelCompanyID { get; set; }

[DataMember]

public string ModelName { get; set; }

}


Answers (3)