use child class as base class in service call

R

Ryan Liu

Hi,

I know this is basic OO concept , and not a problem in local calls.

I know The base type can specify the derived class as a known type using
the KnownTypeAttribute.

What about the opposite?

I want to use a derived class instance as parameter to a WCF service method,
and all properties I need is really in base class, so I just want to use it
as base class, but I get an error:

"....is not expected. Add any types not known statically to the list of
known types - for example, by using the KnownTypeAttribute attribute or by
adding them to the list of known types passed to DataContractSerializer
....."

[KnownType(typeof(MyBaseClass))]
[DataContract]
public class MyChildClass :MyBaseClass
{
public bool LocalFlag {get; set;}
}

Thanks a lot!
Ryan
 
P

Peter Duniho

Ryan said:
Hi,

I know this is basic OO concept , and not a problem in local calls.

Are you sure? Your question seems to indicate you have a very specific
scenario in mind, not just any random object-oriented design hierarchy.
I know The base type can specify the derived class as a known type
using the KnownTypeAttribute.

What about the opposite?

KnownTypeAttribute is not about OOP per se. It's specific to a
particular feature in .NET.
I want to use a derived class instance as parameter to a WCF service
method, and all properties I need is really in base class, so I just
want to use it as base class, but I get an error:

"....is not expected. Add any types not known statically to the list of
known types - for example, by using the KnownTypeAttribute attribute or
by adding them to the list of known types passed to
DataContractSerializer ....."

Why didn't you post a concise-but-complete code example that results in
that error?

You really need to post an actual, concise-but-complete code example
that reliably demonstrates what you're doing and the error you get.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top