views:

1078

answers:

3

I have a class, ReportDef, which is a concrete class that I've decorated with [DataContract] and [DataMember] attributes as needed. ReportDef is in assembly A1 along with my ServiceContract, IReportService. I then have another class, UiReportDef, which derives from ReportDef and is in assembly A2. UiReportDef has no additional state that the service cares about.

I want to invoke my service with an instance of UiReportDef. Is there any way (short of manually constructing a ReportDef instance from UiReportDef) to do this without having my service know about A2? I know about KnownType. I don't want to reference A2.


EDIT: Here's some context that might make my question easier to understand. My ServiceContract implements IReportService which defines a method, RunReport(ReportDef report). ReportDef is decorated with the DataContract attribute, and has private members decorated with DataMember. UiReportDef is in an assembly that depends on UI-related assemblies, etc. I didn't design the existing class hierarchy. I need to pass ReportDefs and UiReportDefs (as ReportDefs) to the new service. Since ReportDef is concrete, I would expect the serializer to treat UiReportDefs as ReportDefs in the absence of any other information.

A: 

WCF is not polymorphic because its not object oriented. Hence this is not possible.

Krzysztof Koźmic
say wha ???
Chad Grant
?Why -1? I did answer your question.
Krzysztof Koźmic
I didn't mark down your answer.
JohnOpincar
Yeah, this was to Deviant. I dont know what was this - getting rid of comeptition by downwoting my answer? Especially considering his answer is wrong.
Krzysztof Koźmic
Your answer is not only wrong, it makes no sense whatsoever.
Chad Grant
I am right. It is not possible, I also explained why. And it makes sense to everyone else.
Krzysztof Koźmic
+1  A: 

I didn't understand you question.

But I think I understand part of it now, you want to deserialize an object in an assembly that has no reference to it?

If so, you can't unless you're willing to do a whole lot of reflection and keep it defined/referenced as "object"

The common way to do this and was trying to explain in my previous answer is that you should use an interface that can be referenced by both client/server.

It is common practice to create stub assemblies consisting of nothing but interfaces for this case.

Or as your comment on your question suggests, you can use DTO objects. http://en.wikipedia.org/wiki/Data_Transfer_Object

Chad Grant
That doesn't work because the run-time type of the object is unchanged by a cast.
JohnOpincar
A: 

Hello,

This thread may probably help a lot : WCF Inheritance and DataContract

controlbreak