<p>What is the best approach to make sure you only need to authenticate once when using an API built on WCF?</p>

<p>My current bindings and behaviors are listed below</p>

<pre><code>    &lt;bindings&gt;
        &lt;wsHttpBinding&gt;
            &lt;binding name="wsHttp"&gt;
                &lt;security mode="TransportWithMessageCredential"&gt;
                    &lt;transport/&gt;
                    &lt;message clientCredentialType="UserName" negotiateServiceCredential="false" establishSecurityContext="true"/&gt;
                &lt;/security&gt;
            &lt;/binding&gt;
        &lt;/wsHttpBinding&gt;
    &lt;/bindings&gt;
    &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
            &lt;behavior name="NorthwindBehavior"&gt;
                &lt;serviceMetadata httpGetEnabled="true"/&gt;
                &lt;serviceAuthorization principalPermissionMode="UseAspNetRoles"/&gt;
                &lt;serviceCredentials&gt;
                    &lt;userNameAuthentication userNamePasswordValidationMode="MembershipProvider"/&gt;
                &lt;/serviceCredentials&gt;
            &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
    &lt;/behaviors&gt;
</code></pre>

<p>Next is what I am using in my client app to authenticate (currently I must do this everytime I want to make a call into WCF)</p>

<pre><code>Dim client As ProductServiceClient = New ProductServiceClient("wsHttpProductService")
client.ClientCredentials.UserName.UserName = "foo"
client.ClientCredentials.UserName.Password = "bar"
Dim ProductList As List(Of Product) = client.GetProducts()
</code></pre>

<p>What I would like to do is auth w/ the API once using these credentials, then get some type of token for the period of time my client application is using the web service project.  I thought establishsecuritycontext=true did this for me?</p>

[{'answer_id': 34177, 'author': 'Ubiguchi', 'author_id': 2562, 'author_profile': 'https://Stackoverflow.com/users/2562', 'pm_score': 1, 'selected': False, 'text': '<p>While I hate to give an answer I\'m not 100% certain of, the lack of responses so far makes me think a potentially correct answer might be okay in this case.</p>\n\n<p>As far as I\'m aware there isn\'t the kind of session token mechanism you\'re looking for out-of-the-box with WCF which means you\'re going to have to do some heavy lifting to get things working in the way you want. I should make it clear there is a session mechanism in WCF but it\'s focused on guaranteeing message orders and is not the ideal tool for creating an authentication session.</p>\n\n<p>I just finished working on a project where we implemented our own session mechanism to handle all manner of legacy SOAP stacks, but I believe the recommended way to implement authenticated sessions is to use a Secure Token Service (STS) like <a href="http://weblogs.asp.net/cibrax/archive/2006/09/08/SAML-_2D00_-STS-implementation-for-WCF.aspx" rel="nofollow noreferrer">Pablo Cibraro\'s</a>.</p>\n\n<p>If you want more details please shout, but I suspect Pablo\'s blog will have more than enough info for you to steam ahead.</p>\n'}, {'answer_id': 36384, 'author': 'Jeremy McGee', 'author_id': 3546, 'author_profile': 'https://Stackoverflow.com/users/3546', 'pm_score': 3, 'selected': True, 'text': '<p>If you\'re on an intranet, Windows authentication can be handled for "free" by configuration alone. </p>\n\n<p>If this isn\'t appropriate, token services work just fine, but for some situations they may be just too much.</p>\n\n<p>The application I\'m working on needed bare-bones authentication. Our server and client run inside a (very secure) intranet, so we didn\'t care too much for the requirement to use an X.509 certificate to encrypt the communication, which is required if you\'re using username authentication.</p>\n\n<p>So we added a <a href="http://www.winterdom.com/weblog/2006/10/02/CustomWCFBehaviorsThroughAppConfig.aspx" rel="nofollow noreferrer">custom behavior</a> to the client that adds the username and (encrypted) password to the message headers, and another custom behavior on the server that verifies them.</p>\n\n<p>All very simple, required no changes to the client side service access layer or the service contract implementation. And as it\'s all done by configuration, if and when we need to move to something a little stronger it\'ll be easy to migrate.</p>\n'}]
['https://Stackoverflow.com/questions/30800', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2701/']