jquery - Push notifications to client with SignalR,WCF duplex service and ASP.Net generic handler? -


i should use developed wcf duplex service send file specified ip address, have call operations should used notifications in client side, came conclusion use signalr newbie in signalr reason don't know signalr can fit or not.

let see codes working on, in asp.net generic handler "sendtoserver" action , using wcf client proxy following:

sendclient sendclient = new sendclient(new sendcallback(),new system.servicemodel.nettcpbinding(),new system.servicemodel.endpointaddress(endpointaddress));          sendclient.operationfailed += sendclient_operationfailed;         sendclient.operationtimedout += sendclient_operationtimedout;         sendclient.sendingfinished += sendclient_sendingfinished;         sendclient.connectionclosed += sendclient_connectionclosed;         sendclient.connectionrefused += sendclient_connectionrefused;         sendclient.instancestored += sendclient_instancestored; sendclient.send(/*array of resources ids*/,  /*server instance*/); 

and event handlers following:

public void sendclient_instancestored(object sender, int currentinstance, int totalinstance, int currentstudy, int totalstudy)     {          //get fired when 1 file sent     }      public void sendclient_connectionrefused(object sender, eventargs e)     {         //connection refused     }      public void sendclient_connectionclosed(object sender, eventargs e)     {         //connection closed     }      public void sendclient_sendingfinished(object sender, eventargs e)     {         //sending finished     }      public void sendclient_operationtimedout(object sender, eventargs e)     {         //operation timed out     }      public void sendclient_operationfailed(object sender, eventargs e)     {         //operation failed     } 

and calling action in js following:

 $.ajax({             cache: false,             type: "post",             url: '../handlers/study/send.ashx',             datatype: "json",             data: {                 action: "sendtoserver",                 hostname: devicehostname, port: deviceport, description: description, ids2send: json.stringify(rows)             },             async: true,             success: function (data) {                 if (data.success == false) {                     $("#loader-send").remove();                     $(".ui-dialog-buttonpane button:contains('send')").button("enable");                     shownoticemessage("can not send server!");                     return;                 }             },             error: function (x, e) {                 $("#loader-send").remove();                 $(".ui-dialog-buttonpane button:contains('send')").button("enable");                 shownoticemessage("can not send server!");             }         }); 

is possible use event handlers notification signalr in client-side after starting $.ajax?

or

is there way(s) without using signalr , how?

thanks in advance.

if needs here solution:

1- signalr should installed.

2- make owin startup class :

   public class startup {     public void configuration(iappbuilder app)     {         // more information on how configure application, visit http://go.microsoft.com/fwlink/?linkid=316888         app.mapsignalr();     } } 

3- define , implement own notification class like:

[hubname("sendnotifier")] public class sendnotifier : hub {     public string currentconnectionid { get; set; }     public void sendstarted()     {         var context = globalhost.connectionmanager.gethubcontext<sendnotifier>();         if (currentconnectionid != null)             context.clients.client(currentconnectionid).sendstarted();     }     public void sendfailed()     {         var context = globalhost.connectionmanager.gethubcontext<sendnotifier>();         if (currentconnectionid != null)             context.clients.client(currentconnectionid).sendfailed();     }     public void instancestored(int currentinstance, int totalinstance, int currentstudy, int totalstudy)     {         var context = globalhost.connectionmanager.gethubcontext<sendnotifier>();         if (currentconnectionid != null)             context.clients.client(currentconnectionid).instancestored(currentinstance, totalinstance, currentstudy, totalstudy);     }     public void sendfinished()     {         var context = globalhost.connectionmanager.gethubcontext<sendnotifier>();         if (currentconnectionid != null)             context.clients.client(currentconnectionid).sendfinished();     }     public void connectionclosed()     {         var context = globalhost.connectionmanager.gethubcontext<sendnotifier>();         if (currentconnectionid != null)             context.clients.client(currentconnectionid).connectionclosed();     }     public void connectiontimedout()     {         var context = globalhost.connectionmanager.gethubcontext<sendnotifier>();         if (currentconnectionid != null)             context.clients.client(currentconnectionid).connectiontimedout();     }     public void connectionrefused()     {         var context = globalhost.connectionmanager.gethubcontext<sendnotifier>();         if (currentconnectionid != null)             context.clients.client(currentconnectionid).connectionrefused();     }      public void connectionfailed()     {         var context = globalhost.connectionmanager.gethubcontext<sendnotifier>();         if (currentconnectionid != null)             context.clients.client(currentconnectionid).connectionfailed();     } } 

4- in event handlers can call our notification method example

 public void sendclient_connectionestablished(object sender, eventargs e)     {         sendnotifier sendnotifier = new sendnotifier();         sendnotifier.currentconnectionid = clientid;         sendnotifier.sendstarted();     } 

note: pasing clientid within ajax request.

and client side code:

 var hub = $.connection.sendnotifier;     hub.client.sendstarted = function () {      };      hub.client.sendfinished = function () {     };      hub.client.sendfailed = function () {     };     //var temp;     hub.client.instancestored = function (currentinstance, totalinstance, currentstudy, totalstudy) {     };      hub.client.connectionclosed = function () {     };      hub.client.connectiontimedout = function () {     };      hub.client.connectionrefused = function () {     };      hub.client.connectionfailed = function () {     };      $.connection.hub.logging = true;     $.connection.hub.start().done(function () {     }); 

and clientid : clientid: $.connection.hub.id

signalr , it's stuff should referenced in head of page.


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -