How can I implement the "Pushing" mode in Asp.Net application

G

Guest

Hi,
As we know,in normal asp.net application, a browser need to send a
request to a server first to refresh its page. Now I need to design a asp.net
application with real-time capability like the MSN Web Messenger. That means
once the session between browser and server has been established, the
browser can get real-time messages with out sending requests periodically.(Or
How to tell the browser that you need to send a new request to refresh the
page.)

Thanks in advance!
 
J

Joyjit Mukherjee

Hi,

you can implement automatic updating of the form using the form's META tag's
Http-Equiv property

<meta http-equiv = "Refresh" Content=60>

this will cause the browser to reload the page every 60 seconds. However,
the it is supported HTML 3.2 onwards compatible browsers.

HTH
Joyjit
 
A

Anders Norås

HTTP is a request-response protocol, so you must send requests periodically
to do this. You can use XMLHTTP to make callbacks to the server without
refreshing the page.

The following code is a XmlHttp factory (courtesy of WebFX):
function XmlHttp() {}

XmlHttp.create = function () {
try {
if (window.XMLHttpRequest) {
var req = new XMLHttpRequest();

// some older versions of Moz did not support the readyState
property
// and the onreadystate event so we patch it!
if (req.readyState == null) {
req.readyState = 1;
req.addEventListener("load", function () {
req.readyState = 4;
if (typeof req.onreadystatechange == "function")
req.onreadystatechange();
}, false);
}

return req;
}
if (window.ActiveXObject) {
return new ActiveXObject(getControlPrefix() + ".XmlHttp");
}
}
catch (ex) {}
// fell through
throw new Error("Your browser does not support XmlHttp objects");
};

function getControlPrefix() {
if (getControlPrefix.prefix)
return getControlPrefix.prefix;

var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];
var o, o2;
for (var i = 0; i < prefixes.length; i++) {
try {
// try to create the objects
o = new ActiveXObject(prefixes + ".XmlHttp");
o2 = new ActiveXObject(prefixes + ".XmlDom");
return getControlPrefix.prefix = prefixes;
}
catch (ex) {};
}

throw new Error("Could not find an installed XML parser");
}
You can use the code above to create XmlHttp objects that can be used to
call back to the server.The following snippet shows how to make an
asyncronous request:function loadAsync(sUri) {
var xmlHttp = XmlHttp.create();
var async = true;
xmlHttp.open("GET", sUri, async);
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4)
doSomething(xmlHttp.responseXML); // responseXML : XmlDocument
}
xmlHttp.send(null);
}You can find examples of how to serialize objects between the server and
the client and back in these blog
entries:http://dotnetjunkies.com/WebLog/ano...s/archive/2004/10/27/29972.aspxRegards,Anders
Noråsblog: http://dotnetjunkies.com/weblog/anoras/"eXseraph"
 
K

Kikoz

This is a big issue. ASP.NET 2.0 will include this functionality but it's
still dificult to implement and maintain and I found that solution to be a
bit complicated in general. It will use the same principals I describe
below, though.

The easiest way to fetch data into page without postback is to use IE
behaviors, namely WebService behavior (Microsoft provides it for free). It
uses ActiveX built in IE 5.5 and does almost the same thing described by
Anders who answered your question earlier.
Because it can be interesting to everyone on this group I'll describe this
stuff a little bit:

The good thing about this is that your page which will render data from
server doesn't have to be written in .net or php or whatever server side
processing you use. It can be simple html page. All ActiveX objects used
here comes with IE 5.5 and above, so you need to make sure that your users
use this version of IE. The WebService behavior itself doesn't come with
IE - you have to get it (see below) and put on your server. You have to use
some sort of data supply/source. The easiest way is to use web service
(asmx) which you can create on your server.
So, the process is relatively simple:

1. You create one or thousand WebServices on your server which html page
will talk to to get the data it needs.
2. You load WebService behavior into your page (it's not a big file, IE will
cache it anyway). Normally I use div tag to hold this behavior and I
"attach" behavior to this div through css class
(.ws{behavior:url(/Blah/HTC/WebService.htc)}).
3. You can use "download" behavior included in IE to load WebService
behavior.
4. Now let's say that you need to pre-fill some text box with all last names
that exist in your db that start with letters user typed into this text box,
much like selection box or IE AutoComplete feature.
5. Your script should detect typing and "ask" the div tag to go to your
server and get particular data (all last names that start with typed
characters) and bring it back by loading it into <xml> tag. I create <xml>
tag on the fly if result from the server is not empty. Then the simple thing
like "var dso = document.all.xmlTagName.recordset;" will give you ADO
recordset with you use to create your selection box, loop through it,
whatever.

It's easy when you've done it before. It looks relatively difficult if you
just starting. Read about it here:
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/webservice/overview.asp

Hope it helps,
Kikoz
 
B

bruce barker

the current problem with the IE web behavior, is that it is disabled with
xp-sp2 for security reasons. you can use it with intranet sites where you
can force the users to trust your site, but it will not work with an
internet site. this is probably why MSN uses a javascript and a hidden frame
to do the polling.

-- bruce (sqlwork.com)



| This is a big issue. ASP.NET 2.0 will include this functionality but it's
| still dificult to implement and maintain and I found that solution to be a
| bit complicated in general. It will use the same principals I describe
| below, though.
|
| The easiest way to fetch data into page without postback is to use IE
| behaviors, namely WebService behavior (Microsoft provides it for free). It
| uses ActiveX built in IE 5.5 and does almost the same thing described by
| Anders who answered your question earlier.
| Because it can be interesting to everyone on this group I'll describe this
| stuff a little bit:
|
| The good thing about this is that your page which will render data from
| server doesn't have to be written in .net or php or whatever server side
| processing you use. It can be simple html page. All ActiveX objects used
| here comes with IE 5.5 and above, so you need to make sure that your users
| use this version of IE. The WebService behavior itself doesn't come with
| IE - you have to get it (see below) and put on your server. You have to
use
| some sort of data supply/source. The easiest way is to use web service
| (asmx) which you can create on your server.
| So, the process is relatively simple:
|
| 1. You create one or thousand WebServices on your server which html page
| will talk to to get the data it needs.
| 2. You load WebService behavior into your page (it's not a big file, IE
will
| cache it anyway). Normally I use div tag to hold this behavior and I
| "attach" behavior to this div through css class
| (.ws{behavior:url(/Blah/HTC/WebService.htc)}).
| 3. You can use "download" behavior included in IE to load WebService
| behavior.
| 4. Now let's say that you need to pre-fill some text box with all last
names
| that exist in your db that start with letters user typed into this text
box,
| much like selection box or IE AutoComplete feature.
| 5. Your script should detect typing and "ask" the div tag to go to your
| server and get particular data (all last names that start with typed
| characters) and bring it back by loading it into <xml> tag. I create
<xml>
| tag on the fly if result from the server is not empty. Then the simple
thing
| like "var dso = document.all.xmlTagName.recordset;" will give you ADO
| recordset with you use to create your selection box, loop through it,
| whatever.
|
| It's easy when you've done it before. It looks relatively difficult if you
| just starting. Read about it here:
|
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/webservice/overview.asp
|
| Hope it helps,
| Kikoz
|
| | > Hi,
| > As we know,in normal asp.net application, a browser need to send a
| > request to a server first to refresh its page. Now I need to design a
| > asp.net
| > application with real-time capability like the MSN Web Messenger. That
| > means
| > once the session between browser and server has been established, the
| > browser can get real-time messages with out sending requests
| > periodically.(Or
| > How to tell the browser that you need to send a new request to refresh
the
| > page.)
| >
| > Thanks in advance!
|
|
 
K

Kikoz

I have numerous implementations of that scenario on several public sites.
WebService behavior doesn't seem to be blocked by SP2 at all. ModalDialog
does change its appearance as well as several other JScript objects but not
behaviors. "Microsoft.XMLDOM" ActiveX object which is used by WebService
behavior is included in IE and trusted by default. All my "no post backs"
code works just fine on all user SP2 machines. Again, although some of those
sites require registration and login, they all "public" and not "intranets"
on some local networks.
 
B

bruce barker

behaviors are the same, but Microsoft's XMLHTTP ActiveX object is not always
enabled.

-- buce (sqlwork.com)


| I have numerous implementations of that scenario on several public sites.
| WebService behavior doesn't seem to be blocked by SP2 at all. ModalDialog
| does change its appearance as well as several other JScript objects but
not
| behaviors. "Microsoft.XMLDOM" ActiveX object which is used by WebService
| behavior is included in IE and trusted by default. All my "no post backs"
| code works just fine on all user SP2 machines. Again, although some of
those
| sites require registration and login, they all "public" and not
"intranets"
| on some local networks.
|
|
|
| > the current problem with the IE web behavior, is that it is disabled
with
| > xp-sp2 for security reasons. you can use it with intranet sites where
you
| > can force the users to trust your site, but it will not work with an
| > internet site. this is probably why MSN uses a javascript and a hidden
| > frame
| > to do the polling.
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top