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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:24:29+00:00 2026-05-11T17:24:29+00:00

I have a Web service and a Web site (both C#) in the same

  • 0

I have a Web service and a Web site (both C#) in the same solution (For now); I also have a class library in the solution. Both the web service and the web site reference this class library.

The web service has a WebMethod that creates an object from the library and returns it. The website invokes this and attempts to put it into a Trainer object (once again, from the same library)

    ProFitWebService.Service serviceConn = new ProFitWebService.Service();
    ProFitLibrary.Trainer authenticatedTrainer = (ProFitLibrary.Trainer)serviceConn.GetAuthenticatedTrainer(_TrainerLogin.UserName);

however the following occurs: “Cannot convert type ProFitWebService.Trainer to ProFitLibrary.Trainer”

Here is the WebMethod:

[WebMethod]
public ProFitLibrary.Trainer GetAuthenticatedTrainer(string email)
{
    ProFitLibrary.Trainer returnTrainer = new ProFitLibrary.Trainer();
    SqlCommand cmd = new SqlCommand("SELECT * FROM Trainers WHERE EmailAddress = '" + email + "'", conn);
    conn.Open();

    SqlDataReader reader;
    reader = cmd.ExecuteReader();

    while (reader.Read())
    {
        returnTrainer.TrainerId = reader.GetInt32(reader.GetOrdinal("TrainerId"));
        returnTrainer.FirstName = reader.GetString(reader.GetOrdinal("FirstName"));
        returnTrainer.LastName = reader.GetString(reader.GetOrdinal("LastName"));
        returnTrainer.PhoneNumber = reader.GetString(reader.GetOrdinal("PhoneNumber"));
        returnTrainer.Address = reader.GetString(reader.GetOrdinal("Address"));
        returnTrainer.City = reader.GetString(reader.GetOrdinal("City"));
        returnTrainer.PostalCode = reader.GetString(reader.GetOrdinal("PostalCode"));
        returnTrainer.EmailAddress = reader.GetString(reader.GetOrdinal("EmailAddress"));
    }

    return returnTrainer;
}

Update: Changing the Trainer object to ProFitWebService.Trainer on the Web site fixed the issue:

    ProFitWebService.Service serviceConn = new ProFitWebService.Service();
    ProFitWebService.Trainer authenticatedTrainer = (ProFitWebService.Trainer)serviceConn.GetAuthenticatedTrainer(_TrainerLogin.UserName);

I think the answer to this is simply that library objects returned from a Web Service will always be type based/prefixed on the service – and I should not reference the class Library from both the Website and the Service – I should just always create the WebService version of the object – ProFitWebService.Trainer etc.

Could someone confirm this as a standard practice when you’re using libraries within a web service? or if I’m making this more difficult then it really is!

  • 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-11T17:24:29+00:00Added an answer on May 11, 2026 at 5:24 pm

    When creating the web reference to your web service you will get proxy classes generated for you. These proxy classes look like the classes from your library, but they are not the same types. You will need to have some method translating between the library version and the proxy versions of these types if you want to treat objects returned from the web service as types from your shared library.

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

Sidebar

Ask A Question

Stats

  • Questions 165k
  • Answers 165k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer MemFree in /proc/meminfo is a count of how many pages… May 12, 2026 at 12:31 pm
  • Editorial Team
    Editorial Team added an answer Firstly, you do not need the ORDER BY on the… May 12, 2026 at 12:31 pm
  • Editorial Team
    Editorial Team added an answer Assuming a fairly regular load, the script will load the… May 12, 2026 at 12:31 pm

Related Questions

We're developing a Python web service and a client web site in parallel. When
We have a DLL used as the middle layer between our website front end
I have a Web application and a WCF service hosted on the same Windows
I'm working on a Web service in Django, and I need to model a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.