tags:

views:

146

answers:

3

We have an Adobe Flex client talking to a .NET server using WebORB. Simplifying things, on the .NET side of things we have a struct that wraps a ulong like this:

public struct MyStruct
{
    private ulong _val;

    public override string ToString()
    {
        return _val.ToString("x16");
    }

    // Parse method
}

And a class:

public class MyClass
{
    public MyStruct Info { get; set; }
}

I want the Flex client to treat MyStruct as a string. So that for the following server method:

public void DoStuff(int i, MyClass b);

It can call it as (C# here as I don't know Flex)

MyClass c = new MyClass();
c.Info = "1234567890ABCDEF"
DoStuff(1, c)

I've tried playing with custom WebORB serializers, but the documentation is a bit scarce. Is this possible? If so how?

I think I can work out how to serialize it, but not the other way. Do I need to write a Custom Serializer on the the Flex end as well?

+1  A: 

why not just overload the DoStuff function to allow a string or MyStruct as the second parameter and deal with it explicitly there?

Though you definitely can build your own custom serializer for the class, and yes documentation sucks on this one.

You would build a custom type writer that implements WebOrb's ITypeWriter public interface ITypeWriter { void write( object obj, IProtocolFormatter writer ); bool isReferenceableType(); }

and map the type with Weborb.Writer.MessageWriter.AddTypeWriter( Type mappedType, ITypeWriter typeWriter );

or map it through the weborb.config or management console.

it's a bit tricky but definitely doable, if you need more help with this let me know and I can provide a couple custom serializers I've written. Also search the yahoo flashorb group for IProtocolFormatter and that should turn up quite a bit. But you you should be just fine with a simple function overload :-P

JTtheGeek
I've oversimplified the question and the custom serializer won't work. I've updated the question to make it a bit clearer what I want to achieve. A custom de-serializer along with the config file changes would be helpful.
Robert Wagner
Gotcha, I'll update within the next 2 days with a concrete example and config, have to pull the files from home.
JTtheGeek
A: 

If you create a TypeConverter for your struct WebOrb should pick it up and use it for conversion.

Sam
+1  A: 

With the release of WebORB for .NET 4.0 came new documentation. Please visit:

http://www.themidnightcoders.com/fileadmin/docs/dotnet/v4/guide/index.html?serializationoverview.htm

This section of the documentation covers serialization and you can drill down to more detailed information on custom serialization.

Hope this helps you!

Cheers, Kathleen

Kathleen Erickson