I should use a developed WCF duplex service to send file to a specified IP address, So I have some call back operations they should be used as notifications in client side, I came to this conclusion to use SignalR but I am newbie in SignalR for this reason don't actually know SignalR can be a good fit to do this or not.
Let see what codes I am working on, in ASP.Net generic handler my "SendToServer" action and using the WCF client proxy is as 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 my event handlers are as following:
public void sendClient_InstanceStored(object sender, int currentInstance, int totalInstance, int currentStudy, int TotalStudy)
{
//Get fired when one file successfully 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 this action in JS is as 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 to Server!");
return;
}
},
error: function (x, e) {
$("#loader-Send").remove();
$(".ui-dialog-buttonpane button:contains('Send')").button("enable");
showNoticeMessage("Can not send to Server!");
}
});
Is it possible to use that event handlers as notification by SignalR in client-side after starting $.ajax?
or
Is there another way(s) to do this without using SignalR and how?
Thanks in advance.