无法序列化Saml2AssertionKeyIdentifierClause

Rog*_*mbe 3 wif thinktecture-ident-server

我正在尝试整合一个声明感知的WCF服务和客户端.

我正在使用thinktecture Identity Server,我通过查看"使用带有WCF/SOAP的令牌"示例将控制台客户端放在一起:

var token = GetSecurityToken();

var binding =
    new WS2007FederationHttpBinding(
        WSFederationHttpSecurityMode.TransportWithMessageCredential);
binding.Security.Message.EstablishSecurityContext = false;

var factory =
    new ChannelFactory<IService1>(
        binding,
        new EndpointAddress("https://localhost:44301/Service1.svc"));
factory.Credentials.SupportInteractive = false;

factory.ConfigureChannelFactory();

var service = factory.CreateChannelWithIssuedToken(token);
var result = service.GetData(42);
Run Code Online (Sandbox Code Playgroud)

我有(看起来像什么)来自STS的有效令牌.

但是,它在调用中引发异常GetData,如下所示:

序列化安全密钥标识符时出错.有关更多详细信息,请参阅内部异常.

内部异常如下:

令牌序列化程序无法序列化"System.IdentityModel.Tokens.Saml2AssertionKeyIdentifierClause".如果这是自定义类型,则必须提供自定义序列化程序.

我能找到的这个问题唯一提到的就是这个问题在MSDN论坛上,但这只是略有关联.

查看调试器,似乎端点行为包括(最终)Saml2SecurityTokenHandler,其他链接暗示的就是所需的全部内容.

我错过了什么?

Ajd*_*eek 8

刚刚从startersts升级到identityserver v2并从saml1.1切换到saml2时,我遇到了完全相同的问题.

我没有生成我的代理,所以解决我的问题是在我的渠道工厂上简单地将Credentials.UseIdentityConfiguration设置为true.如果您生成代理,可能默认情况下不会这样做?或者,如果您使用自定义ChannelFactory,您可能只是忘了像我一样设置它.

var channelFactory = new ChannelFactory<T>(endpointName);
channelFactory.Credentials.UseIdentityConfiguration = true;

var channel = channelFactory.CreateChannelWithIssuedToken(token)
Run Code Online (Sandbox Code Playgroud)

...现在使用没有序列化异常的通道

希望它有所帮助,无需像其他讨论线程所建议的那样在客户端添加system.identityModel部分.