, , COMET, , , . WCF PollingDuplex, , javascript.
, , , . Silverlight, AJAX:
http://www.silverlightshow.net/news/AJAX-Client-for-HTTP-Polling-Duplex-WCF-Channel-in-Microsoft-Silverlight-3-.aspx
UPDATE:
, "omg do pollling"! , , . PollingDuplex, WCF, , , javascript.
, .
2:
, . , HTTP. , , - . , . , . . . , HTTP-- "" .
. , . , , 5 . Chatty, , 4.8s,
. ( 5 ) , , /.
:
sl3duplex.js , JavaScript, HTTP PollingDuplexHttpBinding System.ServiceModel.PollingDuplex.dll
.HTM :
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>AJAX client for HTTP polling duplex WCF channel in Microsoft Silverlight 3</title>
<script src="sl3duplex.js"></script>
<script src="pubsub.js"></script>
<script language="javascript">
var sl3duplex = org.janczuk.sl3duplex;
var proxy = null;
function addNotification(text) {
var notifications = document.getElementById("notifications");
notifications.value += text + "\n";
notifications.scrollTop = notifications.scrollHeight;
}
function alignUIWithConnectionState(connected) {
document.getElementById("topicName").disabled =
document.getElementById("subscribeButton").disabled = connected ? "disabled" : null;
document.getElementById("publishText").disabled = connected ? null : "disabled"
}
function onSubscribe() {
proxy = new sl3duplex.Sl3DuplexProxy({
url: window.location.href.substring(0, window.location.href.lastIndexOf("/")) + "/PubSubService.svc",
onMessageReceived: function(body) {
addNotification("SERVER NOTIFICATION: " + (new sl3duplex.NotificationMessage(body)).text);
},
onError: function(args) {
addNotification("ERROR: " + args.error.message);
alignUIWithConnectionState(false);
}
});
alignUIWithConnectionState(true);
var topic = document.getElementById("topicName").value;
proxy.send({ message: new sl3duplex.SubscribeMessage(topic),
onSendSuccessful: function(args) {
addNotification("CLIENT ACTION: Subscribed to topic " + topic);
}
});
}
function onPublish(event) {
if (event.keyCode == 13) {
var publishText = document.getElementById("publishText");
var content = publishText.value;
publishText.value = "";
var topic = document.getElementById("topicName").value;
proxy.send({ message: new sl3duplex.PublishMessage(topic, content),
onSendSuccessful: function(args) {
addNotification("CLIENT ACTION: Published to topic " + topic + ": " + content);
}
});
}
}
</script>
</head>
<body bgcolor="Tomato">
<table style="width: 640px; font-family: Arial, Helvetica, sans-serif; font-size: 11px;"
cellspacing="2" align="center">
<tr>
<td colspan="2">
Topic to subscribe and publish to:
</td>
</tr>
<tr>
<td style="width: 448px">
<input id="topicName" type="text" value="Dante" style="width: 100%" />
</td>
<td style="width: 192px">
<input id="subscribeButton" type="button" value="Subscribe" style="width: 100%" onclick="onSubscribe();" />
</td>
</tr>
<tr>
<td colspan="2">
</td>
</tr>
<tr>
<td colspan=2>
Notifications:
</td>
</tr>
<tr>
<td colspan="2">
<textarea id="notifications" name="S1" rows="18" readonly="readonly" style="width: 100%;
background-color: ButtonFace"></textarea>
</td>
</tr>
<tr>
<td colspan="2">
</td>
</tr>
<tr>
<td colspan="2">
Enter text to publish and press Enter:
</td>
</tr>
<tr>
<td colspan="2">
<input id="publishText" type="text" style="width: 100%" disabled="disabled" onkeypress="onPublish(event);" />
</td>
</tr>
</table>
</body>
</html>
Silverlight . .JS, , " JavaScript, HTTP" silverlight.