I use wshttpbinding in my service Config and message security. My app works fine but after 10 or 20 min when client calls any method of service, an exception throws because my security token will be expired, and connection can’t work.
One solution is to recreate the connection to make a new token (but I can’t use this because my service contains datacontext and if I recreate the service, the datacontext will be new).
Other solution is to change the security type from message to transport (I tried this solution but nothing changed because another exception was thrown).
I am assuming that when you say datacontext you mean Enitity Framework datacontext.
Your solution appears to depend on the datacontext being available when the client returns. This is a very brittle approach. Even if you increased all the relevant timeouts, you would still get errors if for example the server restarted.
Take a look at WCF Data Services http://msdn.microsoft.com/en-us/data/bb931106.aspx