簡體   English   中英

WCF和大量數據

[英]WCF And Large Amounts Of Data

我希望能夠向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文件)

在代碼中使用此配置。 它將讀取器配額設置為最大值:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM