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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:09:29+00:00 2026-05-14T22:09:29+00:00

I am using a WCF service in my project. This service returns a class

  • 0

I am using a WCF service in my project. This service returns a class called “Store”. I created a new local class which inherits from “Store”. My class is called “ExtendedStore”.
My ExtendedStore looks like this:

class ExtendedStore : StoreManagerService.Store
{
    public int Id;
    ....
}

Now I am using the WCF service to cast to my class using the following code:

StoreManagerService.StoreClient client = new StoreManagerService.StoreClient();
ExtendedStore store = (ExtendedStore) client.GetStore(); // bombs here

I am not able to cast the returned Store class from the service to my ExtendedStore class.
I get the below error message:

Unable to cast object of type
‘ConsoleApplication1.StoreManagerService.Store’
to type
‘ConsoleApplication1.ExtendedStore’.

Shouldn’t I be able to cast it? If not, is there a workaround?

  • 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-14T22:09:30+00:00Added an answer on May 14, 2026 at 10:09 pm

    You should not inherit from a proxy type returned from WCF. Consider that the type does not belong to you!

    You can do some “extension” using the partial class feature of C#, since the proxy classes are generated as partial classes. Instead of creating class ExtendedStore with the Id property, try:

    public partial class Store
    {
        public int Id {get;set;}
    }
    

    This adds an Id property to the Store class. You can also add methods events, etc. in this manner.

    The partial class will need to be defined in the same project tha contains the service reference.


    Consider a project with root namespace “Project”. You have a service reference named “Commerce” to a web service that returns a “Store” object. That means there is a class named Project.Commerce.Store:

    // Proxy code generated by "Add Service Reference":
    namespace Project.Commerce {
        [DataContract]
        public partial class Store {
            [DataMember]
            public string StoreName {get;set;}
            // More data members here
        }
    }
    

    You will create a folder under your project root named “Commerce”. This is so that the namespaces of classes you create there will be “Project.Commerce”. Then create your partial class:

    // This is your code in Store.cs in the new "Commerce" folder:
    namespace Project.Commerce {
        public partial class Store {
            public int Id {get;set;}
            public override string ToString() {
                return String.Format("Store #{0}: {1}", Id, StoreName);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created a simple wcf service that retrieves data from crm 4.0 using the
I have my WCF service, I've created reference to it from MSTest project. Here
I have created WCF service in project. Now using Jquery I am successfully able
I'm creating an app based on SOA, I've created WCF Service Project using Framework
I've added a WCF service reference to a .NET project using this WSDL: https://interop.cmiservices.org/axis/services/CAP1_1?wsdl
I've walked into a project that is using a WCF service for the data
I have developed a Web service using WCF Service Application. This service application is
We are using a WCF service layer to return images from a repository. Some
I have a WCF Service application project , a class library project (acts as
I am new to WCF and created a simple REST service to accept an

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.