views:

80

answers:

1

I have a WCF serivic and Im sharing types with a client in a shared assembly. If the client create a derived class will it be possible to pass back the derived type to the service so that I can read the added properties through reflection ?

I tried but having issues with KnownTypes since the service dont know how to deserialize the derived type.

[Serializable]
public abstract class Car : ICar
{........

//on the client :

[Serializable]
public class MyCar : Car
{......

when passing myCar to Service I get the exception complaining about knownType but I cant add this on the server since I wont know what the client will be sending through and I want to handle extra properties through reflection.

Possible to register client types as knowntypes at runtime ?
Is this maybe the solution ? http://blogs.msdn.com/b/sowmy/archive/2006/03/26/561188.aspx

A: 

Hello,

this is not possible. Both service and client has to know what types will be sent in messages. If you want to use known type you have to define that relation to parent type on the service. Why do you need to know added properties on the server?

Best regards, Ladislav

Ladislav Mrnka
I basically need the client to be able to extend the base class by adding properties (for UI). Then the service will reflect the class and get these extra properties and save it to a database. When Client call GetCar(id) the service will add these properties to the base class and send back. Is there a way to pass(register) the client derived type to the service so the service can register it and use it for this (add to knowntypes + populate with values from db from initial reflection)
DeWet
What about using Dictionary<string, string> for those extra properties? There is actually a way for extra properties from client - your data contract has to implement IExtensibleDataObject. This interface is supposed to be used for different scenario but if you want to use reflection you can may be achieve your requirement. Check: http://geekswithblogs.net/EltonStoneman/archive/2009/04/03/accessing-extended-data-from-iextensibledataobject.aspx
Ladislav Mrnka
The Dictionary<String,String> was my initial approach but with linking the objects to a property grid for editing this didnt work properly since you have the bas class properties coorectly displayd and then have to add a custom editor for the dictionay properties with the user question why are these seperate.Will have a look at your link and replay after some investigation.Thanks
DeWet
I actually think this might do the trick. Will mark as answered :)
DeWet