WCF和大量数据

时间:2014-02-18 09:08:19

标签: c# wcf

我希望能够向我的WCF service发送大量数据,我发送的是客户端收到的List<byte[]>,当前我的应用程序收到套接字中止的错误。

所以我找到了帖子:http://geekswithblogs.net/tmurphy/archive/2011/08/15/sending-large-arrays-with-wcf.aspx

这就是我的联系的建立方式:

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();

我尝试找到maxReceivedMessageSizemaxStringContentLengthmaxArrayLength属性,但我发现只有maxReceivedMessageSize(我的工作没有app.config文件)

1 个答案:

答案 0 :(得分:0)

在代码中使用此配置。它会将读者配额设置为最大值:

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

使用此设置超时。它会将超时设置为5分钟。

tcpBinding.ReceiveTimeout = new TimeSpan(0, 5, 0);
tcpBinding.SendTimeout = new TimeSpan(0, 5, 0);
相关问题