Click here to Skip to main content
14,447,134 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have done the following steps:

1. Client interacts with an STS, which will issue the token.
2. The client uses some other services.

The client needs to present the token to any service it interacts with.
For this reason I used the client and service behavior.
Every time the client calls the service, I put the SamlSecurityToken into the message being sent (using the behavior):
public object BeforeSendRequest(ref Message request, IClientChannel channel)
            UserInfo userInfo = new UserInfo {Username="aaa", password="1234"};
            TokenEngine te = new TokenEngine();

            SamlSecurityToken Token = (SamlSecurityToken)te.CreateToken(userInfo, null);

            //Add the token to the message header
            request.Headers.Add(MessageHeader.CreateHeader("SecurityToken", "", Token));
            return null;

On the service side, I am trying to extract the token from the message:

public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
            //Extract the security token from the received message
            SamlSecurityToken callerToken = request.Headers.GetHeader<samlsecuritytoken>("SecurityToken", "");

            return null;

The problem comes on the service side: I get a null reference exception when trying to get the token.

Am I doing something wrong?
Any alternatives?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100