On Mar 5, 9:41 pm, "John Saunders" <john.saunders at trizetto.com>
wrote:
Hi folks,
I would like to know that is there anyway to change the default
serialization from XML to Binary? If not, what's the best approach
to
accomplish binary serialization under an ASP.NET Web Service? I've
used the following format to do it so far, however, it's really
painless:
public Boolean SyncEntity(ref Byte[] data)
{
//Deserialize the data into an entity object.
//update the entity
//Serialize the entity back into data
}
Is there any official way to do the same thing? (assuming that I'll
develop the proxy myself).
Did you know that Web Services communicate using XML? So, how are you
planning to have binary inside of your XML (which is a text-based
format)?
I also presume from your statement about building the proxy yourself
that
you are only interested in having your own code reference this
service.
Because it's certain that other code will assume that XML is XML, not
binary.
Absolutely. I've developed the proxy myself, and anyone who's going to
consume my exposed services needs to use my hand-made proxy, or else,
it won't be able to communicate with the service. I'm not interested
in interoperability, (in this special application), and therefore...
On the other hand, Binary formatting is much more faster than any
other formatter on the planet. It support Cyclic References, Generic
types and the like whilst the XML Formatter and/or Soap Formatter
don't support them. (This discussion deserves an article I'm working
on already...)
To put the interoperability aside, now the question is that (again) is
there anyway to change the default serialization from XML to Binary
without going through the hard steps of serializing/deserializing each
formal parameter (as well as the return value) of each web method?
Mehdi,
Before you work on the overall serialization issue, have you done a proof
of
concept to see if it's even possible to include binary within XML? Or
will
your web service not use XML at all?
John
Hi,
Well, the answer is that binary information is finally converted to
base64-encoded strings. On the other hand, there are technologies out
there (including DIME) that let you transfer binary information over
the wire. These are all out of question and has got nothing to do with
my question. Lets start from scratch.
Consider a web method, say,
public void UpdateWhateverEntityObject(ref MyEntity entity)
{
}
the MyEntity class uses circular-references, generic types and
whatever that neither XML Serializer, nor the Soap Serializer can
serialize/deserialize that. To make things worst, as soon as the
entity gets updated, it's to reflect new unique identifies or whatever
changes in the data layer to the caller. If there were a way that I
could dictate to the Web Service that it has to serialize/deserialize
data in binary format (and then converts them to the base-64 encoded
string, transfer it over the wire using DIME or whatever), instead of
XML serialization, then it would be possible to take benefit of all
those issues that XML/SOAP serializations cannot handle.
To do so, I changed the above mentioned prototype to:
public void UpdateWhateverEntityObject(ref Byte[] entity)
{
}
This way, I could do the serialization/deserialization myself (as
needed) and everything will just work fine. However, developing such
methods is really pain in the ass (although all are done in 3 lines of
code). I do know that the Byte array eventually is converted to
base-64 encoded string, but I do not care about this.