WCF: Cannot Access a closed stream
<p>I am trying to receive a Stream object in WCF but when i receive it i get a closed Stream.
Following is my code</p>

<pre><code>[OperationContract]
string ProcessPackageUsingStream(FileStream stream, string fileName, string docType, string customerKey, int documentId);
</code></pre>

<p>in implementation i am using this stream object.</p>

<pre><code>string ProcessPackageUsingStream(FileStream stream, string fileName, string docType, string customerKey, int documentId);
{
     //Stream is closed here
}
</code></pre>

<p>Here is my config file</p>

<pre><code>&lt;system.serviceModel&gt;
     &lt;serviceHostingEnvironment aspNetCompatibilityEnabled="true"/&gt;

     &lt;bindings&gt;          
             &lt;basicHttpBinding&gt;
             &lt;binding name="TransferService"   maxReceivedMessageSize="2147483647"  maxBufferSize="2147483647" transferMode="Streamed" &gt;
                 &lt;readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/&gt;
             &lt;security mode="None"&gt; 
             &lt;/security&gt; 
           &lt;/binding&gt;          
         &lt;/basicHttpBinding&gt;
     &lt;/bindings&gt;
     &lt;services&gt;

         &lt;service behaviorConfiguration="TransferServiceBehavior" name="TransferService"&gt;
              &lt;endpoint  address=""
             binding="basicHttpBinding" bindingConfiguration="TransferService"
                contract ="ITransferService"&gt;
                         &lt;/endpoint&gt;
          &lt;/service&gt;
     &lt;/services&gt;
     &lt;behaviors&gt;
         &lt;serviceBehaviors&gt;

             &lt;behavior name="TransferServiceBehavior"&gt;
                 &lt;serviceMetadata httpGetEnabled="true" /&gt;
               &lt;dataContractSerializer maxItemsInObjectGraph="2147483647" /&gt;
                 &lt;serviceDebug includeExceptionDetailInFaults="true" /&gt;
                 &lt;serviceThrottling
                      maxConcurrentCalls="500"
                      maxConcurrentSessions="500"
                      maxConcurrentInstances="500"
                    /&gt;
             &lt;/behavior&gt;
         &lt;/serviceBehaviors&gt;
     &lt;/behaviors&gt;
 &lt;/system.serviceModel&gt;
</code></pre>

<p>On client side i have added reference to this service and used following code</p>

<pre><code>SPCServiceClient service = new SPCServiceClient();
    service.ProcessPackageUsingStream(File.OpenRead(@"D:\Dev\TestData\002160500041.pdf"), "002160500041.pdf", "Test", "VLR@2016", 1211);
</code></pre>