How to transfer large amount of data using WCF?

后端 未结 3 1231
囚心锁ツ
囚心锁ツ 2020-12-19 17:46

We are currently trying to move large amounts of data to a Silverlight 3 client using WCF with PollingDuplex. I have read about the MultiplerMessagesPerPoll in Silverlight

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-19 18:34

    I implemented the suggested solution above. After implementation, I found this link:

    http://msdn.microsoft.com/en-us/library/ms752244.aspx

    I then implemented the Binary writer, as shown below.

    Service Method:

    [OperationContract]
        public Stream GetAllLocationsDataStream(string customerId)
        {
            Stream stream = new MemoryStream();
            try
            {
                Customer customer = ServiceEquipmentManager.GetCustomerAllLocations(customerId);
                DataContractSerializer serializer = new DataContractSerializer(typeof(Customer));
                XmlDictionaryWriter binaryDictionaryWriter = XmlDictionaryWriter.CreateBinaryWriter(stream);
                serializer.WriteObject(binaryDictionaryWriter, customer);
                binaryDictionaryWriter.Flush();
            }
            catch (Exception ex)
            {
                string timestamp;
                ExceptionHelper.HandleExceptionWrapper(ex, "Log Only", out timestamp);
            }
    
            stream.Position = 0;
            return stream;
        }
    

    Client-side Completed Event:

    XmlDictionaryReader binaryDictionaryReader = XmlDictionaryReader.CreateBinaryReader(new MemoryStream(e.Argument as byte[]), XmlDictionaryReaderQuotas.Max);
    
            Customer customer = serializer.ReadObject(binaryDictionaryReader) as Customer;
    

    I checked the difference of my object as shown in the link above, my results are shown below:


    Text = 68,866,216 bytes


    Binary = 49,207,475 bytes (28.5% less than Text)

提交回复
热议问题