WebSharper: Rpc-returned object are unusuable on the client or cause error

爱⌒轻易说出口 提交于 2020-01-06 07:53:10

问题


I have a few server-side objects with inheritrence hierarchy, like this:

[<JavaScriptExport>]
type [<AbstractClass>] A() = ...

[<JavaScriptExport>]
type [<AbstractClass>] B() =
    inherit A()

[<JavaScriptExport>]
type C() =
    inherit B()

The above objects have certain fields and methods, which I have omitted for brevity. All of those can be compiled to javascript -- I receive no build errors.

I have an RPC that would return a server-side created instance of such an object:

module Remoting =
    [<Rpc>]
    let GetObject (arg: string) : Async<A> =
        async {
            return (upcast C() : A)
        }

When I invoke the rpc and debug the relevant javascript in my browser, I see that the retured object is {}. I do not see any server-side errors in the logs.

If I change the signature of the Rpc to be of the concrete type GetObject (arg: string) : Async<C>, I receive an error on the server:

System.Exception: Could not load method (GetObject : System.String -> Microsoft.FSharp.Control.FSharpAsync`1<C>) candidates: [|"(GetObject : System.String -> Microsoft.FSharp.Control.FSharpAsync`1<.C>)"|]

It seems that it looks for a type .C instead of type C (emphasys on the leading dot)

What is the reason for this behavior? Is there a way to get my object instance from the server without having to specify its concrete type?


Update

Interestingly, it works if I replace the RPC call with a client-side method like this:

[<JavaScript>]
let GetObjectClient (arg : string) : A =
    (upcast C() : A)

I suppose there are issues converting the server-side object to its corresponding client counterpart. Still I have no idea how to get over this

来源:https://stackoverflow.com/questions/54053686/websharper-rpc-returned-object-are-unusuable-on-the-client-or-cause-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!