Problmes when serializing Objects containing a Binary

Hi everybody
I am currently facing a problem when trying to serialize RemObjects Entities containing a Binary.

new JavaScriptSerializer().Serialize(new TPerson {
Signature = new RemObjects.SDK.Types.Binary(“Bli-blah-blubb”)
});

This raises a System.InvalidOperationException: Timeouts are not supported on this stream.
Further examination revealed that this is caused by the ReadTimeout Property of the RemObjects.SDK.Types.Binary class.

Is this a known issue. I think, RemObjects entities should be implemented in a fashion that they can be serialized by the supported languages and their libraries.

Best regards

Hello

They are. The BinaryFormatter (and other generic.NET serializers) serialize Binary objects.

However JavaScriptSerializer (and its more advanced variation from Newtonsoft) do not work with MemoryStream and any objects based on it. They do not care to serialize Stream contents and thus are useless in your case.
You need to change the data field type from Binary to Byte and then do something like

new JavaScriptSerializer().Serialize(new TPerson {
Signature = new RemObjects.SDK.Types.Binary("Bli-blah-blubb").ToArray()
});

Regards

Hmm…
The Datatype is defined in the RODL as Binary and I cannot see a byte array type in the Remobjects Service Builder.
Does this mean, I cannot convert a RODL Entity to Json out of the box?

You’ll need one more step to do. You’d need to provide a converter to allow JSON serializer to handle this type. I’ll provide the code in a few.

Depending on the JSON serializer used the result will look like

{  "Signature": "QmxpLWJsYWgtYmx1YmI=" }

or

{"Signature":{"Data":[66,108,105,45,98,108,97,104,45,98,108,117,98,98]}}

Take a look at these code snippets:

There are converter classes for the Newtonsoft JSON serializer and for the JavaScriptSerializer from .NET