3

I'm attempting to put together a claims-aware WCF service and client.

I'm using the thinktecture Identity Server, and I've put together a console client by looking at the "Using a token with WCF/SOAP" example:

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);

I have (what looks like) a valid token from the STS.

However, it throws an exception in the call to GetData, as follows:

There was an error serializing the security key identifier. Please see the inner exception for more details.

The inner exception is as follows:

The token Serializer cannot serialize 'System.IdentityModel.Tokens.Saml2AssertionKeyIdentifierClause'. If this is a custom type you must supply a custom serializer.

The only mention of this problem that I can find is this one on the MSDN forums, but that's only slightly related.

Looking in the debugger, it appears that the endpoint behaviours include (eventually) a Saml2SecurityTokenHandler, which that other link implies is all that's needed.

What am I missing?

EBarr
  • 11,826
  • 7
  • 63
  • 85
Roger Lipscombe
  • 89,048
  • 55
  • 235
  • 380

2 Answers2

8

I had the exact same problem just now when I upgraded from startersts to identityserver v2 and switched from saml1.1 to saml2.

I do not generate my proxies so what solved my problem was to simple set Credentials.UseIdentityConfiguration to true on my channel factory. Perhaps this is not done by default if you generate your proxies? Or if you use your custom ChannelFactory you maybe just forgot to set it as I did.

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

var channel = channelFactory.CreateChannelWithIssuedToken(token)

...use the channel without the serialization exception now

Hope it helps, no need to add a system.identityModel section on the client side as other discussion threads suggest.

Ajden Towfeek
  • 387
  • 2
  • 14
0

Is WIF enabled in your WCF service?

Make sure you have these settings in config:

In the serviceCredentials behavior - useIdentityConfiguration = true In the serviceAuthorization behavior - principalPermissionMode = always

leastprivilege
  • 18,196
  • 1
  • 34
  • 50