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

  • Home
  • SEARCH
  • 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 7748375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:46:07+00:00 2026-06-01T10:46:07+00:00

I have a webservice project (old asmx technology) in which I have a class

  • 0

I have a webservice project (old asmx technology) in which I have a class User. This class has a DateTime property that represents the birthdate of this user. Beside this class, I have another file with a partial class User. In this partial class, I add a property ‘Age’ which returns the age of the user:

public partial class User
{
    public DateTime Age
    {
        get { return DateTime.Now - this.Birthdate; }
    }
}

The reason that this is in a partial class is because the User class code is automatically generated from a config file, and I cannot add code to this class without it being removed every time the code is generated.

Now in my webservice I have a webmethod that returns a list of these Users which it gets from a database:

[WebMethod]
public List<User> GetUsers()
{
    return Database.LoadUsers();
}

Simple enough… Anyway, in a different project now, I add a Service Reference to this webservice. It generates the service client and a User class for me. The problem is: this User class does not contain the properties defined in the partial class (Age in this example)… It seems the webservice doesn’t get this information.

Of course I can create a new partial User class and basically rewrite it in the second project, but I shouldn’t have to, should I? Why doesn’t the webservice recognize the partial class?

  • 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-01T10:46:08+00:00Added an answer on June 1, 2026 at 10:46 am

    Partial classes are not extension methods. They are compiled together into one class in each assembly. You have two options for what you want to do:

    Option 1

    Add the partial class you wrote as a link to the new project. It will be the same file, but linked into the new project. When you go to Add -> Existing Item, select the arrow by Open and choose “Add as Link”.

    Option 2

    Create an extension method:

    public static class DateExtensions
    {
        public TimeSpan GetAge(this DateTime birthDate)
        {
            return DateTime.Now - birthDate;
        }
    }
    

    Then, just add a using statement for whatever namespace your extension class is in, and make sure the project/assembly is referenced, and you can call this:

    // This is your BirthDate property that would come back and is DateTime
    var birthDate = new SomeService().DoSomething().BirthDate;
    
    var age = birthDate.GetAge();
    

    Option 3

    Create a separate project and put the service reference and partial in it. Reference the project (and the necessary framework references) from your using projects.

    I have created an example for you to view/use on GitHub.

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

Sidebar

Related Questions

I have just tried adding a WebService (asmx based) from a WebForms project to
We have an upcoming project to allow an old platform that's only extensible with
We have an SOA based project which has been built from the ground up
We have a netbeans project that has an xsd that we use to create
This week I had to look into a Java WebService project which was using
This the situation: I have one webservice without SSL, which provides two pages for
I have an experimental project in silverlight, that has no database and scarce resources.
1) I have old project that I need to modify. I need to add
I have a project that involves parsing wddx webservice responses. The DOM DocumentBuilder is
I have a project consisting of a windows client (approx. 150 users), a webservice

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.