I am using WCF to a soap endpoint using security mode "TransportWithMessageCredential".
The WCF client/server uses SCT (Security Context Token) to maintain a secure connection, and it is working as intended in the general case.
However, after a period of inactivity, the SCT will be expired and the next method call will cause a MessageSecurityException:
An unsecured or incorrectly secured fault was received from the other party. See the inner FaultException for the fault code and detail
Inner exception:
The message could not be processed. This is most likely because the action 'http://tempuri.org/IMyService/MyMethod' is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings. The security context token would be invalid if the service aborted the channel due to inactivity. To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint's binding.
On subsequent calls, I renew the connection when I see that CommunicationState is Faulted. But I cannot find a way to preemptively check whether the SCT has expired before making my method call.