用IPrincipal作为参数在WCF中传输的时候,比如:client.Ahenticate(Thread.CurrentPrincipal);
总是提示说无法正常序列化,琢磨了好多天都不清楚怎么回事。刚才在看《Programming WCF Service》一书中的“Data Contract Hierarchy”章节的时候,找到了解决方法:在[ServiceContract]下加上:
[ServiceKnownType(typeof(GenericPrincipal))]
[ServiceKnownType(typeof(GenericIdentity))]
其它无法序列化的解决方法也类似。
存笔以录。
![](https://img2024.cnblogs.com/blog/35695/202502/35695-20250207193705881-1356327967.jpg)