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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:34:50+00:00 2026-06-01T08:34:50+00:00

I have a web service in asp.net and I have this model to return:

  • 0

I have a web service in asp.net and I have this model to return:

[Seriazable]
public class Package {

    public int Id { get; set; }
    public string Name { get; set; }
    public string List<Document> Documents { get; set; }

    public Package() { }
}

And in my web service I have these methods:

[WebMethod]
public Package GetPackage(int Id);


[WebMethod]
public List<Package> FindPackage();

The first method is ok (all properties are returned and it works fine), but the on second method I don’t want to expose Documents property, only the Id and Name… how can I do it?

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-06-01T08:34:52+00:00Added an answer on June 1, 2026 at 8:34 am

    Since you don’t want the consuming client to have access to the documents, you should create a separate view model1 class for the second method to serve. Something like this:

    public class SimplePackageViewModel
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }
    

    You can then instantiate objects of this class using some mapping utility, for example AutoMapper, and return those instead:

    [WebMethod]
    public List<SimplePackageViewModel> FindPackage();
    [WebMethod]
    public Package GetPackage(int id);
    

    Karel Frajtak suggested you use a similar view model object also for the package, but since they are identical that will only clutter your code – as long as the Package is a simple POCO, there is no need for an extra class. However, if you are using some O/R-mapper that keeps track of Package instances, it is wise not to expose them to the client app. Then you should instead do what Karel suggested, and create a POCO view model class for the Package as well.


    1) Some call them Data Transfer Objects (DTO). I call them View Models. I bet there are ten other names out there too – for all practical purposes, they are the same.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider an ASP.NET Web API service that redirects public class ThisController : ApiController {
I have a web service in ASP.NET being called by a time-sensitive process. If
I have created Web-Service in asp.net with c# . Now i want to pass
I am trying to call a web service from asp.net 3.5 application. I have
I have loaded an byte array image from a web service to my asp.net
i have an ASP.NET web service that returning a custom entity object (Staff): [WebMethod]
I have an ASP.net web service that I'm using for a web application which
I have an ASP.NET web service running that accepts both HTTP POST and SOAP
I have an ASP.NET web service that I can access via a windows program
I have a asp.net website and I am accessing that web service from my

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.