Note that there are some explanatory texts on larger screens.

plurals
  1. POWCF Service hosted on IIS website with TransferMode = Streamed throws w3wp.exe OutOfMemory exception?
    primarykey
    data
    text
    <p>I have build a WCF service to upload and download files.</p> <p>Service: Hosted on IIS asp.net website:</p> <pre><code>[ServiceContract] public interface IFileTransferService { [OperationContract(IsOneWay = true)] void Upload(FileTransferRequest request); } [MessageContract()] public class FileTransferRequest { [MessageHeader(MustUnderstand = true)] public string FileName; [MessageBodyMember(Order = 1)] public System.IO.Stream Data; } [AspNetCompatibilityRequirements(RequirementsMode= AspNetCompatibilityRequirementsMode.Required)] public class FileTransferService : IFileTransferService { public FileTransferService() { HttpContext httpContext = HttpContext.Current; if (httpContext != null) { httpContext.Response.BufferOutput = false; } } public void Upload(FileTransferRequest request) { string fileName = System.Guid.NewGuid().ToString() + request.FileName; if (ConfigurationManager.AppSettings["UploadPath"] == null) { throw new ApplicationException("Missing upload path"); } string uploadPath = "/OutputFeeds"; string filePath = Path.Combine(Path.GetFullPath(HttpContext.Current.Server.MapPath(uploadPath)), fileName); FileStream fs = null; try { fs = File.Create(filePath); byte[] buffer = new byte[1024]; int read = 0; while ((read = request.Data.Read(buffer, 0, buffer.Length)) != 0) { fs.Write(buffer, 0, read); } } finally { if (fs != null) { fs.Close(); fs.Dispose(); } if (request.Data != null) { request.Data.Close(); request.Data.Dispose(); } } } } </code></pre> <p>Server config:</p> <pre><code>&lt;system.serviceModel&gt; &lt;serviceHostingEnvironment aspNetCompatibilityEnabled="true"&gt; &lt;/serviceHostingEnvironment&gt; &lt;bindings&gt; &lt;basicHttpBinding&gt; &lt;binding name="HttpBinding_MTOM" messageEncoding="Mtom" transferMode="Streamed" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"&gt; &lt;security mode="None"&gt; &lt;transport clientCredentialType="None" /&gt; &lt;/security&gt; &lt;/binding&gt; &lt;/bindings&gt; &lt;services&gt; &lt;service behaviorConfiguration="FileTransferServiceBehavior" name="FileTransferService"&gt; &lt;endpoint address="" binding="basicHttpBinding" bindingConfiguration="HttpBinding_MTOM" contract="IFileTransferService"&gt; &lt;identity&gt; &lt;dns value="localhost" /&gt; &lt;/identity&gt; &lt;/endpoint&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="FileTransferServiceBehavior"&gt; &lt;serviceMetadata httpGetEnabled="true" /&gt; &lt;serviceDebug includeExceptionDetailInFaults="false" /&gt; &lt;/behavior&gt; &lt;/serviceBehaviors&gt; &lt;/behaviors&gt; &lt;/system.serviceModel&gt; </code></pre> <p>Client: Calling the above service from console application:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;configuration&gt; &lt;system.serviceModel&gt; &lt;bindings&gt; &lt;basicHttpBinding&gt; &lt;binding name="BasicHttpBinding_IFileTransferService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Mtom" textEncoding="utf-8" transferMode="Streamed" useDefaultWebProxy="true"&gt; &lt;readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /&gt; &lt;security mode="None"&gt; &lt;transport clientCredentialType="None" proxyCredentialType="None" realm=""&gt; &lt;extendedProtectionPolicy policyEnforcement="Never" /&gt; &lt;/transport&gt; &lt;message clientCredentialType="UserName" algorithmSuite="Default" /&gt; &lt;/security&gt; &lt;/binding&gt; &lt;/basicHttpBinding&gt; &lt;/bindings&gt; &lt;client&gt; &lt;endpoint address="http://ht/FileTransferService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IFileTransferService" contract="HobbyTown.IFileTransferService" name="BasicHttpBinding_IFileTransferService" /&gt; &lt;/client&gt; &lt;/system.serviceModel&gt; &lt;/configuration&gt; </code></pre> <p>Client Upload Code:</p> <pre><code> string inputFile = @"C:\Client\InputFeeds\FullInventory.zip"; using (FileStream fs = new FileStream(inputFile, FileMode.Open)) { FileTransferServiceClient proxy = new FileTransferServiceClient(); proxy.Upload("Inventory.Zip", fs); //proxy.Upload(trIn); } </code></pre> <p>Note: If I change transfer mode to buffered in the client it works and however if Make the transfer mode on the client to Streamed it doesn't and throws outofmemory error.</p> <p>Another <a href="http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/d36bf53e-dcb1-4df4-b26a-f692e85e6637" rel="nofollow">post for same problem</a> </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload