Question

I have a WCF service and I'm 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 don't 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

Was it helpful?

Solution

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?

OTHER TIPS

I think there is a way.

I vaguely remember that when I studied WCF, I met ExtensionData which should be a mechanism to get everything that does not match the serialization of the class. for example, if you enable ExtensionData and you are in this situation

//Server
public class GenericRQ
{
    public string GenericProperty {get;set;}
}


public Service GenericService
{
    Public void GenericMethod(GenericRQ RQ)
    {
    }

}

// client

Public class MoreSpecificRQ : GenericRQ
{
    public string SpecificProperty {get;set;}
}

At

Public void GenericMethod(GenericRQ RQ)
    {
    // the serializer adds automatically in RQ.ExtensionData everything that has come and that does not match the class GenericRQ.

    }

On how to enable ExtensionData you to easily search on the web

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top