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 7668403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:21:18+00:00 2026-05-31T15:21:18+00:00

I have been working on a wcf application and have been trying to return

  • 0

I have been working on a wcf application and have been trying to return a list of names from an sql server database. My main issue is that my select * statement only returns the last value of the list. Here is the code.

Name Model:

public Name GetName()
    {

        Name name = new Name();

        using (SqlCommand objcmd = new SqlCommand("Select * from Names", sql))
        {
            SqlDataReader reader = objcmd.ExecuteReader();
            while (reader.Read())
            {
                name.NameID = reader.GetInt32(0);
                name.Name = reader["Name"].ToString();
            }
        }
        return name;
    }

.svc:

public Name GetNames()
    {

        Name serviceName = new Name();
        NamesModel model = new NamesModel();
        Name modelName = model.GetName();
        serviceName.NameID = modelName.NameID;
        serviceName.Name = modelName.Name;

        model.Close();

        return serviceName;
    }

NameService:

[OperationContract]
    [WebGet(ResponseFormat = WebMessageFormat.Json, UriTemplate = "getnames")]
    Name GetNames();

I have tried to print the value out to a list but there seems to be a disconnect somewhere. Any help would be great. Thanks.

  • 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-31T15:21:19+00:00Added an answer on May 31, 2026 at 3:21 pm

    Not sure, but the code shown definitevely doesn’t return any list….
    I try to guess your intentions and suggest to change in this way ….

       public List<Name> GetNames() 
       { 
    
            List<Name> names = new List<Name>(); 
    
            using (SqlCommand objcmd = new SqlCommand("Select * from Names", sql)) 
            { 
                SqlDataReader reader = objcmd.ExecuteReader(); 
                while (reader.Read()) 
                { 
                    Name name = new Name();
                    name.NameID = reader.GetInt32(0); 
                    name.Name = reader["Name"].ToString(); 
                    names.Add(name);
                } 
            } 
            return names; 
        } 
    

    .svc:

        public List<Name> GetNames() 
        { 
    
            NamesModel model = new NamesModel(); 
            List<Name> names = model.GetNames(); 
            // ?? serviceName.NameID = modelName.NameID;  
            // ?? serviceName.Name = modelName.Name; 
    
            model.Close(); 
    
            return names; 
        } 
    

    NameService:

    [OperationContract] 
        [WebGet(ResponseFormat = WebMessageFormat.Json, UriTemplate = "getnames")] 
        List<Name> GetNames(); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been attempting to compile/run a sample WCF application from Juval Lowy's website
I have been working on a WCF service which will return a Base64 encoded
I have a WCF service as part of a client/server application I am working
I have been working on a WCF service library where hopefully all the business
I have been working with a string[] array in C# that gets returned from
I am new to WCF services. I have been working with WCF for over
I have been working on this issue for a few days now and can't
hi friends I have been working WCF since past one week. I have written
I have been working on setting up a WCF REST service in .NET 4.0.
I have a WCF service that has been working perfectly, and something has changed

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.