Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
571 views
in Technique[技术] by (71.8m points)

serialization - How to serialize a derived type as its base type with WCF

I have a common library with some objects in it. Then I have a service project that references the common library and creates some derived types from objects in the common library.

I want my service to serialize the derived types as their base types defined in the common library.

I cannot use KnownTypes on the objects in the common library because I don't want the common library referencing the service assemblies.

So how can I have wcf serialize the derived types as their base types?

I wish I could do something like...

[DataContract(SerializeAsType = typeof(BaseType))] public class DerivedType : BaseType { }

Is anything like this possible?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

We have just "solved" this issue by setting inherited class [DataContract(Name="BaseClass")]. It works even if inherited class is internal and defined in another project.

Hope it helps.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...