invoke

The invoke method is for calling a method on a controller. You can also pass some data that will end up as parameters on the server-side method.

You have already seen examples using invoke and it is pretty simple.

Example 1

Calling the method Bar on the controller Foo without parameters.

Client side

<script>
   var conn = new xsockets.client('ws://localhost:4502');
   var foo = conn.controller('foo');

   // code removed for readability

   foo.invoke('bar');
</script>

Server side

public class Foo : XSocketController
{
    public async Task Bar()
    {
        // Logic here
    }
}

Example 2

Calling the method Bar on the controller Foo with a parameter.

Client side

<script>
   var conn = new xsockets.client('ws://localhost:4502');
   var foo = conn.controller('foo');

   // code removed for readability

   foo.invoke('bar','Hello from JavaScript');
</script>

Server side

public class Foo : XSocketController
{
    public async Task Bar(string message)
    {
        // Logic here
    }
}

Example 3

Calling the method Bar on the controller Foo with a complex parameter.

Client side

<script>
   var conn = new xsockets.client('ws://localhost:4502');
   var foo = conn.controller('foo');

   // code removed for readability

   foo.invoke('bar',{name:'Uffe', Age:39});
</script>

Server side

public class Person
{
    public string Name{get;set;}
    public int Age{get;set;}
}
public class Foo : XSocketController
{
    public async Task Bar(Person p)
    {
        // Logic here
    }
}

results matching ""

    No results matching ""