WebOrb - 将对象序列化为字符串

发布于 2024-08-24 12:09:07 字数 735 浏览 3 评论 0原文

我们有一个 Adob​​e Flex 客户端使用 WebORB 与 .NET 服务器通信。简化一下,在 .NET 方面,我们有一个像这样包装 ulong 的结构:

public struct MyStruct
{
    private ulong _val;

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

    // Parse method
}

和一个类:

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

我希望 Flex 客户端将 MyStruct 视为字符串。因此,对于以下服务器方法:

public void DoStuff(int i, MyClass b);

它可以将其称为(这里是 C#,因为我不知道 Flex)

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

我尝试过使用自定义 WebORB 序列化器,但文档有点稀缺。这可能吗?如果是这样怎么办?

我想我可以找出如何序列化它,但不能以其他方式。我是否还需要在 Flex 端编写自定义序列化程序?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

小耗子 2024-08-31 12:09:07

随着 .NET 4.0 的 WebORB 的发布,出现了新的文档。请访问:

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

文档的此部分介绍序列化,您可以深入了解有关自定义序列化的更多详细信息。

希望这对您有帮助!

干杯,
凯瑟琳

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

§普罗旺斯的薰衣草 2024-08-31 12:09:07

为什么不直接重载 DoStuff 函数以允许字符串或 MyStruct 作为第二个参数并在那里显式处理它?

尽管您绝对可以为该类构建自己的自定义序列化器,但是文档在这个方面很糟糕。

您将构建一个实现 WebOrb 的 ITypeWriter 的自定义类型编写器
公共接口 ITypeWriter
{
void write( 对象 obj, IProtocolFormatter writer );
bool isReferenceableType();

使用 Weborb.Writer.MessageWriter.AddTypeWriter( TypemappedType, ITypeWriter typeWriter ); 映射类型

或通过 weborb.config 或管理控制台映射它。

这有点棘手,但绝对可行,如果您需要更多帮助,请告诉我,我可以提供几个我编写的自定义序列化器。还可以在 yahoo flashorb 组中搜索 IProtocolFormatter,应该会出现很多。但你应该可以接受简单的函数重载:-P

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

心欲静而疯不止 2024-08-31 12:09:07

如果您为结构体创建一个 TypeConverter ,WebOrb 应该选择它并使用它进行转换。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文