Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7049687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:03:07+00:00 2026-05-28T03:03:07+00:00

I am calling on a WCF Data Services v3 Odata service. I am having

  • 0

I am calling on a WCF Data Services v3 Odata service.
I am having trouble getting my collection filled in the below example. I am able to get a json string of the 3 people, but if I try and get a custom collection filled, the collection has a count = 0.

HttpClient client = new HttpClient();

client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

client.BaseAddress = new Uri("http://localhost:7500/Wcf1.svc/People");

HttpResponseMessage resp = client.GetAsync("").Result;

string jsonString = resp.Content.ReadAsStringAsync().Result;

List<Person> personCollection = resp.Content.ReadAsAsync<List<Person>>().Result;

jsonString has 3 people in it.

personCollection has a count = 0.

the jsonString looks like this:

{"d":[
{"__metadata":{"id":"http://localhost:7500/Wcf1.svc/People(1)",
"uri":"http://localhost:7500/Wcf1.svc/People(1)",
"type":"WcfService1.Person"},
"ID":1,"Fname":"Fred","Lname":"Peters","Address1":"123 Main"},

 {"__metadata":{"id":"http://localhost:7500/Wcf1.svc/People(2)",
"uri":"http://localhost:7500/Wcf1.svc/People(2)",
"type":"WcfService1.Person"},
"ID":2,"Fname":"John","Lname":"Smith","Address1":"123 Oak"},

{"__metadata":{"id":"http://localhost:7500/Wcf1.svc/People(3)",
"uri":"http://localhost:7500/Wcf1.svc/People(3)",
"type":"WcfService1.Person"},
"ID":3,"Fname":"Tom","Lname":"Anders","Address1":"123 Hill St."}]}

I must be doing something wrong, please point out my error if you can.

Thanks.
Terrence

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:03:08+00:00Added an answer on May 28, 2026 at 3:03 am

    Your content is not a List<Person>

    Paste your Json into json2csharp and you’ll see it.

    To get a better overview what your response content is, download Json Viewer – this is a screenshot of your data:

    enter image description here

    As you can see: the Persons are a property of the Json root object.

    If you wanted to use your code from above, the Json should have to look like this (or you need to access the data in the given structure mapping you classes according to the Json):

    [{"__metadata":{"id":"http://localhost:7500/Wcf1.svc/People(1)",
    "uri":"http://localhost:7500/Wcf1.svc/People(1)",
    "type":"WcfService1.Person"},
    "ID":1,"Fname":"Fred","Lname":"Peters","Address1":"123 Main"},
    
     {"__metadata":{"id":"http://localhost:7500/Wcf1.svc/People(2)",
    "uri":"http://localhost:7500/Wcf1.svc/People(2)",
    "type":"WcfService1.Person"},
    "ID":2,"Fname":"John","Lname":"Smith","Address1":"123 Oak"},
    
    {"__metadata":{"id":"http://localhost:7500/Wcf1.svc/People(3)",
    "uri":"http://localhost:7500/Wcf1.svc/People(3)",
    "type":"WcfService1.Person"},
    "ID":3,"Fname":"Tom","Lname":"Anders","Address1":"123 Hill St."}]}]
    

    Update:

    You should be able to parse your initially posted Json like this:

    var json = JsonValue.Parse(response.Content.ReadAsStringAsync().Result);
    var arr = json["d"];
    var contact1 = arr[0];
    var fname = result1["Fname"];
    

    I have done a blog post on JsonValue and JsonArray recently. It’s server side, but it should point you the direction.

    2nd Update:

    Using the classes from the json2csharp.com output, you can do this:

    public class Metadata
    {
        public string id { get; set; }
        public string uri { get; set; }
        public string type { get; set; }
    }
    
    public class D
    {
        public Metadata __metadata { get; set; }
        public int ID { get; set; }
        public string Fname { get; set; }
        public string Lname { get; set; }
        public string Address1 { get; set; }
    }
    
    public class RootObject
    {
        public List<D> d { get; set; }
    }
    

    Usage:

    var root = resp.Content.ReadAsAsync<RootObject>().Result;
    var persons = root.d;
    var person1 = persons[0];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Am getting following error message on calling WCF service: The formatter threw an exception
Hi All I am currently having an issue calling a WCF service from a
I am using calling web services and using WCF generated service-reference on the client.
I am getting the following error using WCF, calling the a WCF Service on
I am calling a WCF Service using AJAX.NET and wanted to know if the
Will calling close on my WCF service kill all resources or set them up
Scenario: WCF client app, calling a web-service (JAVA) operation, wich requires a complex object
I have a WCF service that I am calling from multiple clients. I need
There is a Silverlight (4.0) application that is calling to WCF-service. During 1st call
I'm a noob to calling WCF web services, so am hoping this is an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.