title: WCF Service service call to stream endpoint fails on 3rd call
body: <p>quick overview of what I've got here:</p>
  
  <p>WCF Soap service is running over HTTPS, with Message credential of type certificate.  I've got 2 endpoints that I use (besides mex), 1 for my normal service calls, the other for streaming files.  Here's my web.config for the service (edited some names of items):</p>
  
  <pre><code>&lt;bindings&gt;
    &lt;wsHttpBinding&gt;
      &lt;binding name="wsHttpEndpointBinding"&gt;
        &lt;security mode="TransportWithMessageCredential"&gt;
          &lt;message clientCredentialType="Certificate" /&gt;
        &lt;/security&gt;
      &lt;/binding&gt;
    &lt;/wsHttpBinding&gt;
    &lt;basicHttpBinding&gt;
        &lt;binding name="streamBinding" transferMode="Streamed" messageEncoding="Mtom" maxReceivedMessageSize="2147483646"&gt;
            &lt;security mode="TransportWithMessageCredential"&gt;
                &lt;message clientCredentialType="Certificate" /&gt;
            &lt;/security&gt;
        &lt;/binding&gt;
    &lt;/basicHttpBinding&gt;        
  &lt;/bindings&gt;
  &lt;services&gt;
    &lt;service behaviorConfiguration="Services.Behavior" name="MyInterface"&gt;
      &lt;endpoint address="" binding="wsHttpBinding" bindingConfiguration="wsHttpEndpointBinding" name="wsHttpEndpoint" contract="IMyInterface" /&gt;
      &lt;endpoint address="stream" binding="basicHttpBinding" bindingConfiguration="streamBinding" name="streamEndpoint" contract="IMyInterface" /&gt;
      &lt;endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /&gt;
    &lt;/service&gt;
  &lt;/services&gt;
  &lt;behaviors&gt;
    &lt;serviceBehaviors&gt;
      &lt;behavior name="Service.Behavior"&gt;
        &lt;serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" /&gt;
        &lt;serviceDebug includeExceptionDetailInFaults="true" /&gt;
        &lt;dataContractSerializer maxItemsInObjectGraph="2147483646" /&gt;
        &lt;serviceCredentials&gt;
          &lt;serviceCertificate findValue="CN=Server.Temp.Dev" /&gt;
        &lt;/serviceCredentials&gt;
      &lt;/behavior&gt;
    &lt;/serviceBehaviors&gt;
  &lt;/behaviors&gt;
  </code></pre>
  
  <p>The service has a method, DownloadDocument, that I'm testing.  Here's the signature:</p>
  
  <p>DocumentDownloadResponse DownloadDocument(DocumentDownloadRequest request);</p>
  
  <p>It's worth noting the the service throws Exceptions when the data passed in is not valid, and DownloadDocument catches those exceptions and passes back the error message in the response object.</p>
  
  <p>The DocumentDownloadRequest looks like this:</p>
  
  <pre><code>[MessageContract]
  public class DocumentDownloadRequest
  {
      [MessageHeader]
      public string SecurityToken { get; set; }
  
      [MessageHeader]
      public string LoginName { get; set; }
  
      [MessageHeader]
      public string DocumentId { get; set; }
  }
  </code></pre>
  
  <p>And DownloadDocumentResponse:</p>
  
  <pre><code>[MessageContract]
  public class DocumentDownloadResponse : ServiceResponse&lt;Stream&gt;
  {
      public DocumentDownloadResponse()
      {
          Data = Stream.Null;
      }
  
      [MessageHeader(MustUnderstand = true)]
      public bool Success { get; set; }
  
      [MessageHeader(MustUnderstand = true)]
      public string ErrorMessage { get; set; }
  
      [MessageBodyMember(Order = 1)]
      public Stream Data { get; set; }
  }
  </code></pre>
  
  <p>Here's how I call it from the client:</p>
  
  <pre><code>        var soapServiceClient = new SoapServiceClient("streamEndpoint");
          bool success;
          Stream stream;
          string errorMessage =
              soapServiceClient.DownloadDocument(documentId, loginName, securityToken, out success, out stream);
  
          serviceClient.Close();
  </code></pre>
  
  <p>Where SecurityToken and LoginName are items that need to validates.  What's strange is that from my test client, when I call DownloadDocument with valid data, I am able to download the file perfectly as many times as I want.  However, if I pass in an invalid LoginName or SecurityToken, I get error messages indicating incorrect data (as expected).  If I pass in invalid data 3 times, however, the client times out.  Running the service locally I don't get this issue, everythign runs as expected.  Strangely enough, whenI run with fiddler open, I don't get this issue.  When I run with the service on my dev server, I have the problems.</p>
  
  <p>The configuration on the dev server matches what I run locally.  Using the SvcTraceTool I don't see any errors, except that it only documents the first 2 successful calls, and not the one that failed.  It almost makes me think the endpoint just closed itself somehow.</p>
  
  <p>Cliffs:</p>
  
  <p>1) Service with 2 endpoints, one of if which is streaming (the one I'm concerned with).
  2) Able to use streaming endpoint to call method to Download files with valid data
  3) Service correctly catches bad data 2 times, hangs the 3rd time.  No logs in SvcTraceTool, client times out.</p>
  
  <p>Any ideas?</p>
  
  <p>Thanks</p>