我有一个datacontract作为我的WCF接口的一部分,继承自IIdentity:
[DataContract]
public class AuthenticationIdentity : IIdentity
{
//implements IIdentity...
}
该服务返回我的AuthenticationIdentity对象就好了。但是,当我尝试在客户端上进行明显的演员表时:
AuthenticationIdentity aId = client.GetID();
IIdentity id = aId;
我收到一条投诉,即AuthenticationIdentity无法投放到IIdentity。我已经尝试将ServiceKnownTypes添加到接口:
[ServiceKnownType(typeof(AuthenticationIdentity))]
[ServiceKnownType(typeof(IIdentity))]
但仍然没有运气。有什么想法吗?
答案 0 :(得分:3)
如果您控制线的两侧(由于您想要转换为IIdentity
,它看起来像你一样),您可以从共享组件中引用DataContract
。然后,您可以在服务和使用者之间使用svcutil to share the DataContracts。或者,如果你想完全删除svcutil,你可以编写自己的代理来使用共享程序集。