I implemented the proposed solution above. After implementation, I found this link:
http://msdn.microsoft.com/en-us/library/ms752244.aspx
Then I implemented binary notation as 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; }
Completed event on the client side:
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 text)
source share