How to extend WCF returned class properly?

Posted by vikasde on Stack Overflow See other posts from Stack Overflow or by vikasde
Published on 2010-05-20T18:27:23Z Indexed on 2010/05/20 18:30 UTC
Read the original article Hit count: 208

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about wcf

Related posts about casting