Welcome to CrankyGoblin.Com Sign in | Join | Help

Public Class GeoffAppleby

Inherits Microsoft.VisualBasic.MVP : Implements IBrainFart
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)
Posted: Tuesday, November 30, 2004 6:51 PM by Geoff Appleby

Comments

Dave said:

If I'm not mistaken, just mark your class as <Serializable()> and the web service will take care of the rest. For example, if you want to return a class named Address from your web service, create an Address class and add the <Serializable()> attribute to it. Double-check this of course, but I think that might do it. Of course, I could be off my rocker...
# November 30, 2004 9:40 PM

Geoff Appleby said:

Oh, if only it was that easy. For example, any class that derives from IDictionary can't be just passed through.

Most of the time you're exactly right, tho :)
# November 30, 2004 10:00 PM

Dave said:

Ah... I see where you're coming from now. I figured you would have tried the simple solution by now :-)
# November 30, 2004 10:22 PM

An attempt at structured thought. said:

Can I touch it?
# December 17, 2004 9:29 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

To submit your comment, click on these pictures:
  • Shocked Geoff
  • Geoff's dad's tongue
  • Geoff's little sister's pussy
Gaptcha Image - No Peeking! Gaptcha Image - No Peeking! Gaptcha Image - No Peeking!
Gaptcha Image - No Peeking! Gaptcha Image - No Peeking! Gaptcha Image - No Peeking!
Gaptcha Image - No Peeking! Gaptcha Image - No Peeking! Gaptcha Image - No Peeking!
Can't recognise the people in these pictures? Look here for a quick introduction.
There's a time limit for you to get your comment submitted before this set of pictures expires. If you think it's been longer than 10 minutes, get some new pictures first (you won't lose what you've typed so far).
Get some new pictures 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS