title: Securing WCF service using basicHttpBinding which supports streaming
body: <p>My question is in regards to the best (aka "least painful") way to secure access to a WCF service that is only exposed to our company's internal users. The goal is to ensure that the service is only accessed via a single Windows forms application that each of our users has installed. When the service is called, I want the service to be able to validate that it was called from the permitted application.</p>
  
  <p>The service to be secured uses basicHttpBinding, which supports streaming, so I believe I am limited to Transport level security.</p>
  
  <p>Below are simplified versions of the <code>&lt;bindings&gt;</code> and <code>&lt;services&gt;</code> sections from my service's config file.</p>
  
  <pre><code>&lt;bindings&gt;
    &lt;basicHttpBinding&gt;
      &lt;binding name="Service1Binding" transferMode="Streamed"/&gt;    
    &lt;/basicHttpBinding&gt;
  &lt;/bindings&gt;
  
  &lt;services&gt;
      &lt;service name="WCFServiceSecurity.Service1" 
          behaviorConfiguration="WCFServiceSecurity.Service1Behavior"&gt;
          &lt;endpoint address=""
              binding="basicHttpBinding"
              contract="WCFServiceSecurity.IService1"
              bindingConfiguration="Service1Binding"/&gt;
          &lt;endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/&gt;
      &lt;/service&gt;
  &lt;/services&gt;
  </code></pre>
  
  <p>Can anyone offer some details as to what actions I would need to take in order to implement security on this service?</p>
  
  <p><em>Note: I'm new to WCF and am not familiar with security at all, so let me know if I haven't provided enough detail.</em></p>
  
  <hr>
  
  <h3>UPDATE:</h3>
  
  <p>As <a href="https://stackoverflow.com/questions/845423/securing-wcf-service-using-basichttpbinding-which-supports-streaming/845640#845640">suggested by marc_s</a>, I'd like to secure the WCF service using some sort of username/password mechanism. This gives a little more direction towards an answer, but I'm still somewhat blurry on <em>how</em> to actually do this. </p>
  
  <p>Because my service requires streaming to be enabled, I have to use basicHttpBinding and Transport level security (right?); further to that, the method contained in my service can only accept a Stream object.</p>
  
  <p>Taking those constraints into consideration along with my preference to use username/password validation...</p>
  
  <ul>
  <li>How should I modify my service's config file to force username/password credentials to be supplied?</li>
  <li>How will my service validate the supplied credentials?</li>
  <li>How will my client application pass credentials the service when making a call?</li>
  <li>Will this require using SSL and, if so, will all client machines require a certificate as well?</li>
  </ul>
  
  <hr>
  
  <h3>UPDATE:</h3>
  
  <p>After explaining the trouble I've been having with securing this service to my boss, I was given the go-ahead to try the Windows Authentication route. Sadly, I've had no luck in implementing this type of authentication with my Streamed service (argh). After making the appropriate changes (as outlined <a href="http://msdn.microsoft.com/en-us/library/cc949012.aspx" rel="nofollow noreferrer">here</a> - the only exception being that my <code>transferMode="Streamed"</code>) and accessing my service, I was presented with the following error:</p>
  
  <blockquote>
    <p>HTTP request streaming cannot be used in conjunction with HTTP authentication. Either disable request streaming or specify anonymous HTTP authentication.</p>
  </blockquote>
  
  <p>I then stumbled upon the following quote <a href="http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/f76011d7-29ba-4d27-9dc4-62ae72ca7721" rel="nofollow noreferrer">here</a> which offers some clarification:</p>
  
  <blockquote>
    <p><strong>You can't do transport auth. with streaming.</strong> If you have to use HTTP request streaming, you'll have to run without security.</p>
    
    <p>The way security works is:</p>
    
    <p>WCF Client makes an http request to the Server.</p>
    
    <p>The Server responds with something saying, "You aren't authorized, send me a basic/digest/etc credential."</p>
    
    <p>The Client gets that response and resends its message with the credentials tacked on.</p>
    
    <p>Now the Server gets the message, verifies the credentials, and continues.
    Request Streaming isn't designed to work with that security pattern. If it did, it would be really slow, since the Client would send the entire stream, get the message from the Server that it wasn't authorized, then it would have to resend the entire stream with credentials.</p>
  </blockquote>
  
  <p>So now I'm looking for opinions, <strong>how would you secure your streaming-enabled WCF service?</strong> As mentioned previously, some sort of username/password mechanism would be preferred. Feel free to think outside the box on this one... </p>
  
  <p>Any help is <strong>greatly</strong> appreciated!</p>