开发者

WCF - DataContract that inherits from an interface

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 Au开发者_如何学CthenticationIdentity 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜