title: Passing NetworkCredential through WCF service to use with EWS API
body: <p>I have a WCF service running, hosted on IIS7 which is exposed using a netTcp endpoint, and configured using Windows authentication (<code>Transport</code> security and <code>clientCredentialType="Windows"</code>), and this all works fine.</p>
  
  <p>In the service I am using the EWS API to send email, and check inboxes on the Exchange server. I have this working in part, in so far as at the moment in development I have manually specified the Credentials property by creating a <code>NetworkCredential</code> object to pass in.</p>
  
  <p>What I want to do though is use the identity of the user calling the service so I can send mail as them and iterate through their inbox.</p>
  
  <p>I can get access to the calling user details by using</p>
  
  <pre><code>ServiceSecurityContext.Current.PrimaryIdentity
  </code></pre>
  
  <p>but this returns an <code>IIdentity</code> object and not the credentials I need to create a connection to the Exchange server.</p>
  
  <p>I cannot obviously create a <code>NetworkCredential</code> object without the password, which I don't have, and from what I can see I cannot create a <code>NetworkCredential</code> from the <code>IIdentity</code> object.</p>
  
  <p>There must be a way to achieve this. All suggestions welcome.</p>