Here is what your server-side function should look like:

1
2
3
4
5
    [<Remote>]
    let Receive (input: string) =      
        async {
            System.IO.File.WriteAllText(@"D:/myDatabase.txt", "Server received data: " + input)
        }

and to call it from Client.fs, you need:

1
2
3
4
5
6
7
8
9
...
            button [
                on.click (fun _ _ ->
                    async {
                        do! Server.Receive rvInput.Value
                    } |> Async.Start
                )
            ] [text "Receive"]
...
By on 2/16/2018 7:45 PM ()

Hi, WebSharper's client side can call methods that are themselves in [<JavaScript>] scope or marked [<Remote>] for remote calls. The error message is not mentioning the second option, but that is what you need here (same as the sample function DoSomething has it too).

You will also need to make the remote function to not send over an obj but a string. Remote function arguments are deserialized based on type information and cannot be obj. For example in client code, use Server.receive rvInput.Value. (rvInput is a reactive variable for which .Value contains current value)

Note that if you want to return a value to the server, the remote function must be an async. Here, just for logging, returning unit works too, but then you have no way on the server to determine if the logging was successful. By returning an async<unit>, you can catch errors in the client code if you want to guard against connection or server errors. Again, the sample code in the template gives some guidance.

By on 2/16/2018 6:49 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper