Click here to Skip to main content
14,983,545 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I created a RESTful WCF service and hosted it in IIS. When I query My service for 'Get' method I get the response as following:

{"GetDeviceDataResult":{"FirstName":"abc","Id":"2","LastName":"def"}}


Client Application:

I am trying to create a Client application, which will query the server using the HTTPWebRequest, here is my snippet but I am getting the OutputResponse.deviceResult object as NULL while deserializing the json data.
C#
public void Start()
{
  string url = "http://10.10.12.44/BLEService/BLEService.svc/GetDeviceData/2";

                HttpWebRequest GETRequest = (HttpWebRequest)WebRequest.Create(url);
                GETRequest.Method = "GET";
                string jsonString = string.Empty;
                // System.Net.ServicePointManager.Expect100Continue = false;
                using (HttpWebResponse response = GETRequest.GetResponse() as HttpWebResponse)
                {
                    // Get the response stream                                 
                    StreamReader reader = new StreamReader(response.GetResponseStream());

                    jsonString = reader.ReadToEnd();
                }
                System.Web.Script.Serialization.JavaScriptSerializer jsSerializer =
                    new System.Web.Script.Serialization.JavaScriptSerializer { MaxJsonLength = 2147483647 };

                ResponseData Outputresponse = jsSerializer.Deserialize<resp>(jsonString);
}


Here is my class for ResponseData

  public class GetDeviceDataResult
   {
       public string FirstName { get; set; }
       public string LastName { get; set; }
       public string Id { get; set; }
   }

   public class ResponseData
   {
       public GetDeviceDataResult deviceResult { get; set; }
   }

Any help would be appreciated. Thanks
Posted
Updated 25-Sep-14 15:22pm
v2

1 solution

Here is the answer:

I changed the Instance name of GetDeviceDataResult to the "GetDeviceDataResult" in ResponseData class. Previously I had this as deviceResult

C#
public class GetDeviceDataResult
   {
       public string FirstName { get; set; }
       public string LastName { get; set; }
       public string Id { get; set; }
   }

   public class ResponseData
   {
       public GetDeviceDataResult GetDeviceDataResult { get; set; }
   }
   

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