There is a WCF service

using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace WCF { public class ServerService : IServerService { public ServerService() { Console.WriteLine("Server init"); } public void UploadFiles(Dictionary<string, byte[]> files) { string pathToUploadFolder = @"C:\Upload"; foreach (var file in files) { File.WriteAllBytes(pathToUploadFolder + "\\" + file.Key, file.Value); } } } } 

For its hosting, a console application is used. App.Config Servers:

 <?xml version="1.0" encoding="utf-8" ?> <configuration> <system.serviceModel> <services> <service name="WCF.ServerService" behaviorConfiguration="ServerServiceMEXBehavior"> <endpoint address="" binding="basicHttpBinding" contract="WCF.IServerService" /> <endpoint address="" binding="netTcpBinding" contract="WCF.IServerService"/> <endpoint address="" binding="netNamedPipeBinding" contract="WCF.IServerService" /> <host> <baseAddresses> <add baseAddress="http://localhost:8008/UploadService"/> <add baseAddress="net.tcp://localhsot:8009/UploadService"/> <add baseAddress="net.pipe://localhost/UploadService"/> </baseAddresses> </host> </service> </services> <behaviors> <serviceBehaviors> <behavior name="ServerServiceMEXBehavior"> <serviceMetadata httpGetEnabled="true"/> </behavior> </serviceBehaviors> </behaviors> 

Written by the simplest client to this service:

 using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using Client.ServiceReference1; namespace Client { class Program { static void Main(string[] args) { using (ServerServiceClient client = new ServerServiceClient("NetNamedPipeBinding_IServerService")) { Console.WriteLine("Send file"); string name = "test.rar"; var fileBytes = File.ReadAllBytes(@"C:\Users\Pol\Desktop\test.rar"); Dictionary<string, byte[]> dictionary = new Dictionary<string, byte[]>(); dictionary.Add(name, fileBytes); client.UploadFiles(dictionary); Console.WriteLine("End"); } } } } 

Client App.Config:

 <?xml version="1.0" encoding="utf-8" ?> <configuration> <system.serviceModel> <bindings> <basicHttpBinding> <binding name="BasicHttpBinding_IServerService" /> </basicHttpBinding> <netNamedPipeBinding> <binding name="NetNamedPipeBinding_IServerService" /> </netNamedPipeBinding> <netTcpBinding> <binding name="NetTcpBinding_IServerService" /> </netTcpBinding> </bindings> <client> <endpoint address="http://localhost:8008/UploadService" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IServerService" contract="ServiceReference1.IServerService" name="BasicHttpBinding_IServerService" /> <endpoint address="net.tcp://localhsot:8009/UploadService" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IServerService" contract="ServiceReference1.IServerService" name="NetTcpBinding_IServerService"> <identity> <userPrincipalName value="Pol-PC\Pol" /> </identity> </endpoint> <endpoint address="net.pipe://localhost/UploadService" binding="netNamedPipeBinding" bindingConfiguration="NetNamedPipeBinding_IServerService" contract="ServiceReference1.IServerService" name="NetNamedPipeBinding_IServerService"> <identity> <userPrincipalName value="Pol-PC\Pol" /> </identity> </endpoint> </client> </system.serviceModel> </configuration> 

I would like to know how it is necessary to change the configuration so that it is possible to send files of ~ 2Gb volume via tcp connection and named pipes

    2 answers 2

    From my point of view, only by turning on WCF Streaming . Either implement something like this on your own, otherwise WCF will try to keep the entire 2 GB file in memory to create a message to send.

      Theoretically, you can configure the maxReceivedMessageSize and maxReceivedMessageSize parameters in this way.

       <binding maxBufferSize="64000000" maxReceivedMessageSize="64000000" /> 

      The maximum value in the documentation should allow up to Int64.Max , but according to reviews, only up to Int32.Max . If the first is fair, you obviously have enough to transfer 2 GB, the second is just under 2 GB.

      Nevertheless, I agree with the opinion above that it is better in this situation, in accordance with the recommendations, to use Streaming.