Hooking Serialization in a Web Service Call.
I've talked a little bit in the past about custom XML serialization of HashTables. This is fine and dandy, and works a treat, but I have a small problem.
The reason I worked so hard to find a nice way to serialize a HashTable and stuff like that is so I can send it to/from a web service. But the end result is pretty ugly, in that you have to serialize it yourself, then send it to a WebMethod that has to deserialize it back again. Or, the WebMethod has to serialize it and the client has to deserialize it back again.
Part of the beauty of web services is that a lot of the time you just specify your class as a parameter or return value, and it automagically gets serialized.
But what about these special classes I have that needs extra work? I've been trying to find a nice way to get it serialized my way, but not have to explicitly call it way. I thought i was onto a winner with the ISerializable interface, but it has two problems that i've noticed:
- You have to do the hard work yourself of testing if a value is the same as the DefaultValueAttribute (so you can not bother to serialize it and save on bandwidth). The same applies for any other Attribute that you might set on your properties that effect serialization. The beauty of a lot of the attributes is that you set a few markers, and it's all taken care of (DefaultValue and XMLIgnore are two good examples)
- It doesn't get invoked when serialized for a web method call. I managed to get the ISerializable methods called when i used a SoapFormatter manually, and i imagine other ones like it do too, but just passing the class through a web method did nothing.
So does anyone have any advice? I'm sick of making WebMethods that have string parameters and string return values when they aren't that at all.
Help me.
Please.
You know you want to :)
Listening to: wish - alien ant farm - (4:20)