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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:32:28+00:00 2026-06-02T02:32:28+00:00

I have a web service I’m calling that does a dupe check based on

  • 0

I have a web service I’m calling that does a dupe check based on email, firstName and lastName. The object I am getting back from the business layer is very large and has way more data than I need to pass back. In my web service function, I would like to only pass back 10 fields via JSON. Instead of making a new class with those 10 fields, I was looking to loop through my large return object and just make a list or array of anonymous objects with those 10 fields in it instead.

I know I can make an anonymous array of anonymous object manually like this

obj.DataSource = new[]
{
    new {  Text = "Silverlight",  Count = 10,  Link = "/Tags/Silverlight"  },
    new {  Text = "IIS 7",        Count = 11,  Link = "http://iis.net"     }, 
    new {  Text = "IE 8",         Count = 12,  Link = "/Tags/IE8"          }, 
    new {  Text = "C#",           Count = 13,  Link = "/Tags/C#"           },
    new {  Text = "Azure",        Count = 13,  Link = "?Tag=Azure"         } 
};

My issue is that I want to do that exact thing except by looping through my big object and only pulling out the fields I need to return.

private class DupeReturn
{
    public string FirstName;
    public string LastName;
    public string Phone;
    public string Owner;
    public string Address;
    public string City;
    public string State;
    public string Zip;
    public string LastModified;
}

[WebMethod]
[System.Web.Script.Services.ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string CheckForDupes(string Email, string FirstName, string LastName)
{
    contact[] list = Services.Contact.GetDupes(Email, FirstName, LastName);
    if (list != null && list.Length > 0)
    {
        List<DupeReturn> dupes = new List<DupeReturn> { };
        foreach (contact i in list)
        {
            DupeReturn currentObj = new DupeReturn
            {
                FirstName = i.firstname,
                LastName = i.lastname,
                Phone = i.telephone1,
                Owner = i.ownerid.ToString(),
                Address = i.address1_line1,
                City = i.address1_city,
                State = i.address1_stateorprovince,
                Zip = i.address1_postalcode,
                LastModified = i.ctca_lastactivityon.ToString()
            };
            dupes.Add(currentObj);
        }
        return Newtonsoft.Json.JsonConvert.SerializeObject(dupes);    
    }
}

I really don’t want to have to make that additional private class if I don’t have to. Any help would be appreciated.

  • 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-06-02T02:32:30+00:00Added an answer on June 2, 2026 at 2:32 am

    Using LINQ you can create a list of your anonymous type.

    var dupes = list.Select(i => new { FirstName = i.firstname,
                                       LastName = i.lastname,
                                       Phone = i.telephone1,
                                       Owner = i.ownerid.ToString(),
                                       Address = i.address1_line1,
                                       City = i.address1_city,
                                       State = i.address1_stateorprovince,
                                       Zip = i.address1_postalcode,
                                       LastModified = i.ctca_lastactivityon.ToString()
                                        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web service that is running and generates a WSDL file based
I have a web service (ASMX) and in it, a web method that does
I have a web service that requires special headers to be sent in the
I have a web service that stores data in a local SQL Server 2008
I have a web service that is running on IIS (6 or 7, doesn't
I have a web service that takes a byte[] and saves it. This works
I have a Web Service with Just one Web Method that returns a boolean
I have web service in PHP which gets dateTime object (from asp) . I
I have web service written that generates some data...can I call the web service
I have a web service that I have a rewrite on. I need to

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.