Not able to call client method on OnDisconnected

Sid M

I've a disconnect method in TestHub(which is inherited by Hub) class for signal R. I'm not able to call javascript method fnDeleteCustomer from OnDisconnected method, however same same js method gets called on Connect method. What I'm doing wrong?

 public override Task OnDisconnected()
        {
            try
            {
                 var customer = ConnectedUsers.Find(x => x.ConnectionID == Context.ConnectionId);
                if (customer!=null)
                {
                  Clients.Client(customer.ConnectionID).fnDeleteCustomer(customer.UserId);
                  return base.OnDisconnected();
                }
            }
            catch { };
            return null;
        }
Anton Kiprianov

According to MSDN:

Occurs when a connection disconnects from this hub instance.

So you have no any alive connection and you cannot access the client hub and its methods.

I suppose you should use client-side disconnected event:

$.connection.hub.disconnected(function() {
    $.connection.hub.fnDeleteCustomer(userId);
});

More information about signalr lifetime events can be found here.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Not able to call method in a gem

Not able to call method from class

execute script before OnDisconnected method

not able to await a casted method call - syntax error

Not able to call returned method from instance name

Not able to call a static method in node js

Not able to call SAVE method on Model object Laravel

Not able to call another controller method in codeigniter

Superclass reference not able to call subclass method in Java

Not able to call the the method of the child component in react

LARAVEL - Not able to call a function inside a controller method

I am not able to call a method out of scope

Not able to call a method from InfoWindow in react js

"OnDisconnected(): no suitable method found to override" - SignalR

WCF Server call Client Method

Spy actual method call, not able to stub the calls in the actual method by mocking

Not able to call method within another method of the same class JS

Client app able to call API Locally but unable to do it in IIS

Twillio Client To Client Call ios Never Recieve call method is didReceiveIncomingConnection

Not able to connect to DB in php with mariadb gssapi, authentication method unknown to client

Not able to call a method of PHP using $http.get in Angular JS

Why i am not able to call adapter method from my activity

Not able to call simple web api post method from jquery

Not able to call a method when a feature/marker is selected in OpenLayers

How am I able to call a method on a null object?

Able to use pointer to function to call private method of an external class

Discord Python, After a client.close() call i want to be able to call client.start() again, but somehow the client loggs in multiple times

Meteor method call returns undefined on the client but not on the server

Can't call client method from server