xSocket custom method not working.

15 views
Skip to first unread message

Squall Leohart

unread,
Jul 5, 2016, 10:56:27 PM7/5/16
to XSockets.NET Developer forum

Hello,

I tried to create custom methods:

namespace Server.Modules
{

   
/// <summary>

   
/// Implement/Override your custom actionmethods, events etc in this real-time MVC controller

   
/// </summary>

   
[XSocketMetadata("controller")]

   
public class MyController : XSocketController

   
{

       
public override async Task OnMessage(IMessage message)

       
{

            await
this.InvokeToAll(message);

       
}




       
public async Task Foo()

       
{

           
//Send a message to all clients with the topic 'say'

            await
this.InvokeToAll("Foo: Hello to all", "foo");

       
}




       
public async Task Bar(string message)

       
{

           
//Send out the message that was sent in to all clients

            await
this.InvokeToAll(string.Format("Bar: {0}", message), "bar");

       
}

   
}

}


But when i tried to call it, it go to OnMessage, not Foo.




Log-20160706.txt

Ulf Björklund

unread,
Jul 6, 2016, 1:31:33 AM7/6/16
to XSockets.NET Developer forum
Hi Squall

The "controller" string is a suffix in the controller names.

So naming your "MyController" to "controller" causes the issue.
Ofcourse it should be handled by throwing an exception telling you that "controller" is a bad name.

We will patch that in the next release. We do not see it as a critical fix since naming it anything but "controller" will be a workaround.
Btw I would remove the XSocketMetadata attribute and just call the controller with the name "my" since the controller part is a suffix (as mentioned).

Thanks for posting your findings!
Uffe

Squall Leohart

unread,
Jul 6, 2016, 3:01:04 AM7/6/16
to XSockets.NET Developer forum
Thanks.
That made me confuse for a while.
Reply all
Reply to author
Forward
0 new messages