I have done the following steps:
- Client interacts with an STS, which will issue the token.
- 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("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?