views:

245

answers:

1

I have a datacontract as part of my WCF Interface that inherits from IIdentity:

 [DataContract]
 public class AuthenticationIdentity : IIdentity
 {
    //implements IIdentity...
 }

The service returns my AuthenticationIdentity objects just fine. However, when I try and do the obvious cast on the client:

AuthenticationIdentity aId = client.GetID();
IIdentity id = aId;

I get a complaint that AuthenticationIdentity cannot be cast to IIdentity. I've tried adding the ServiceKnownTypes to the interface:

[ServiceKnownType(typeof(AuthenticationIdentity))]
[ServiceKnownType(typeof(IIdentity))]

but still no luck. Any ideas?

+1  A: 

If you control both sides of the wire (which it looks like you do since you want to cast to IIdentity), you can reference your DataContract from a shared assembly. Then you can use svcutil to share the DataContracts between the service and the consumer. Or, if you wanted to cut out svcutil altogether, you could write your own proxy to use the shared assembly.

Tuzo