也就是說,序列化和反序列化這壹大段數據是沒有問題的。主要問題仍然出現在WCF大會的信息中。
設置ReaderQuotas的屬性,該屬性設置消息的復雜性。
感覺這種癥狀很像被DOS殺死的感覺,於是想到了ReaderQuotas。
以下是我嘗試過的壹個例子。
C#代碼
public byte[]get mays(){ DataContractSerializer DCZ = newDataContractSerializer(type of(List & lt;May & gt));列表& ltMay & gtlist =新列表& ltMay & gt();for(int I = 0;我& lt30000;i++){ May tmp = new May { Name = DateTime。now . ToString(" yyyy-MM-DD ")};列表。添加(tmp);}使用(memory stream fs = new memory stream()){ DCZ。WriteObject(fs,list);返回fs。to array();} }
-
用妳的方式完成它。客戶需要設置它。
netTcpBinding。reader quotas . MaxArrayLength = 2147483647;
netTcpBinding。reader quotas . MaxStringContentLength = 2147483647;
netTcpBinding。reader quotas . MaxBytesPerRead = 2147483647;
// -
系統。診斷。秒表myWatch =新系統。Diagnostics .秒表();
我的手表。start();
//taxi info[]taxi infos = position service。GetAllTaxiInfos();
byte[] sds = PositionService。get mays();
我的手表。stop();
控制臺。WriteLine("耗時:"+mywatch。經過的毫秒+“ms”);
memory stream memory = new memory stream(SDS);
XmlDictionaryReader讀取器=
XmlDictionaryReader。CreateTextReader(memory,new XmlDictionaryReaderQuotas());
DataContractSerializer ser = new DataContractSerializer(type of(List & lt;TaxiInfo & gt));
//反序列化數據並從實例中讀取它。
列表& ltTaxiInfo & gt反序列化人員=
(列表& ltTaxiInfo & gt)ser。ReadObject(reader,true);
讀者。close();
//控制臺。WriteLine(deserialized person);
所以那沒問題。