3

I looked for some other topics here as well, but I didn't find a solution to my problem yet.

Imagine the following:
I've a very simple ServiceContract with different OperationContracts. One of these OperationContracts is a simple use-case "download a data transfer object".

The Service looks like:

...
[OperationContract]
DTO Download(strind Id)
...

Class DTO looks like:

[DataContract]
public class DTO
{
     [DataMember]
     public string Id;

     [DataMember]
     public byte[] Data;
}

Of course it's very simple and it works fine, but I need to allocate the byte[] in DTO by myself!

My Code is part of a framework componenent and it's working in parallel under massive memory restrictions. I don't want WCF to allocate all the byte[] and I don't want the ManagedHeap to deallocate them all again. I need to share and reuse all parallel existing buffers.

So when I finished my serialization I will reuse the buffer on serverside. On clientside I want WCF to read into my buffer!

I tried some solutions with own XmlObjectSerialiers and own OperationBehaviors, but it didn't work yet.

Does anyone have any other ideas?

Mike
  • 47,263
  • 29
  • 113
  • 177
Marcel N
  • 35
  • 3
  • Why do you want your Data to be included in the datacontract as member if you do not want to send it to the client? – Peter Oct 31 '12 at 13:39
  • Of course I want to send data to the client. But I want wcf to past the incoming data in my already allocated byte[]. – Marcel N Oct 31 '12 at 14:29

1 Answers1

0

Update:

I found a first working solution using an own Serializer:XmlObjectSerializer, an own IContractBehavior and an own DataContractSerializerOperationBehavior.

While reading from XmlDictionaryReader during Deserialization I use the following snippet:

public bool DeserializeFrom(XmlDictionaryReader source)
{
     ...
     readBytes = source.ReadElementContentAsBase64(MyOwnAlreadyAllocatedBuffer, offset, toRead);
     ...
}

This works, but it's still a bit slower than the DataContractSerializer.

Any other options?

Notice: I just want to transfer already binary serialized data!

Marcel N
  • 35
  • 3