【发布时间】:2015-10-10 10:03:56
【问题描述】:
我应该使用开发的 WCF 双工服务将文件发送到指定的 IP 地址, 所以我有一些回调操作,它们应该用作客户端的通知,我得出这个结论是使用 SignalR,但我是 SignalR 的新手,因为这个原因实际上并不知道 SignalR 是否适合这样做.
让我们看看我正在处理哪些代码,在 ASP.Net 通用处理程序中我的“SendToServer”操作并使用 WCF 客户端代理如下:
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*/);
我的事件处理程序如下:
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
}
在JS中调用这个动作如下:
$.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!");
}
});
是否可以在启动$.ajax 后在客户端使用该事件处理程序作为 SignalR 的通知?
或
还有其他方法可以在不使用 SignalR 的情况下执行此操作吗?
提前致谢。
【问题讨论】:
标签: jquery asp.net notifications push-notification signalr