0

I want to be able to send large amount of data to my WCF service, what i am sending is List<byte[]> that the client received and currently my application get an error that socket aborted.

so i found ths thread: http://geekswithblogs.net/tmurphy/archive/2011/08/15/sending-large-arrays-with-wcf.aspx

this is how my connection is estanlished:

string urlService = "net.tcp://localhost:8000/myApp";
ServiceHost host = new ServiceHost(typeof(pp.classes.service1));
host.Opening += new EventHandler(host_Opening);
host.Opened += new EventHandler(host_Opened);
host.Closing += new EventHandler(host_Closing);
host.Closed += new EventHandler(host_Closed);

NetTcpBinding tcpBinding = new NetTcpBinding();
tcpBinding.TransactionFlow = false;
tcpBinding.Security.Transport.ProtectionLevel = System.Net.Security.ProtectionLevel.EncryptAndSign;
tcpBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
tcpBinding.Security.Mode = SecurityMode.None; // <- Very crucial
pp.classes.service1 ser = new pp.classes.service1();
host.AddServiceEndpoint(typeof(pp.classes.IService1), tcpBinding, urlService);
ServiceMetadataBehavior metadataBehavior;
metadataBehavior = host.Description.Behaviors.Find<ServiceMetadataBehavior>();
if (metadataBehavior == null)
{
    // Create the proxy object that is generated via the svcutil.exe tool
    metadataBehavior = new ServiceMetadataBehavior();
    metadataBehavior.HttpGetUrl = new Uri("http://localhost:8001/myApp");
    metadataBehavior.HttpGetEnabled = true;
    metadataBehavior.ToString();
    host.Description.Behaviors.Add(metadataBehavior);
    string urlMeta = metadataBehavior.HttpGetUrl.ToString();
}

host.Open();

I try to find maxReceivedMessageSize, maxStringContentLength and maxArrayLength properties but i found only maxReceivedMessageSize (i am working without app.config file)

Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
user3271698
  • 145
  • 3
  • 9
  • 19
  • I don't have one, i am hosing WCF service in my Winforms gui – user3271698 Feb 18 '14 at 09:12
  • Probably Duplicated: http://stackoverflow.com/questions/969479/modify-endpoint-readerquotas-programatically – ilansch Feb 18 '14 at 09:13
  • First of all I love the comment *<- Very crucial* without any further explanation why. That's great. Also you should add the WCF configuration to your `app.config`, which makes things much easier to configure (yes, you can do that even if you're hosting the service yourself). Thirdly, you'll probably want to use a streamed service, which allows you to transfer very large amounts of data through streams. This question seems to sum it up well: http://stackoverflow.com/questions/14479885/wcf-streaming-large-data-500mb-1gb-on-a-self-hosted-service – Thorsten Dittmar Feb 18 '14 at 09:16
  • How can i add WCF configuration to my app.config ? – user3271698 Feb 18 '14 at 10:14
  • Did you see the link in my comment? There's an example. Basically you add a `ServiceConfiguration` to the `app.config` where you configure bindings, binding configurations, etc. and then all you need to do is call the `ServiceHost` constructor with `typeof()` parameter. Otherwise there are many tutorials out there which you can easily google. – Thorsten Dittmar Feb 18 '14 at 11:01

1 Answers1

0

Use this config in code. It will set the reader quotas to the max:

XmlDictionaryReaderQuotas quotas = new XmlDictionaryReaderQuotas();
quotas.MaxDepth = 2147483647;
quotas.MaxStringContentLength = 2147483647;
quotas.MaxArrayLength = 2147483647;
quotas.MaxBytesPerRead = 2147483647;
quotas.MaxNameTableCharCount = 2147483647;
tcpBinding.ReaderQuotas = quotas;

Set the timeout using this. It will set the timeout to 5 minutes.

tcpBinding.ReceiveTimeout = new TimeSpan(0, 5, 0);
tcpBinding.SendTimeout = new TimeSpan(0, 5, 0);
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325