I have a WCF Service that requires a security token issued by a separate WCF STS Service. This all works just dandy. In my application, I use the service like so:
MyServiceClient myService = new MyServiceClient();
myService.Open();
myService.DoStuff();
The STS Service is called to get a token and the token is used to call the service method DoStuff.
Once the initial handshake is over, though, the myService
object has the token cached and re-uses it until it expires. This is fine behavior and all, but how would I force it to refresh the token?
myService.ClientCredentials.Invalidate(); // something like this?
Such that if I called DoStuff() again it would know it needs to go to the STS again much as it did the first time.
Am I stuck just making a new proxy class object, i.e. myService = new MyServiceClient();
? This works but it seems like the nuclear bomb solution.
Alternatively, is there a way to just manually get a new token and replace the current one, i.e. myService.ClientCredentials.Renew();
?
If I have to make a custom ClientCredentials class to do this, how would I implement the above example methods?