Queuing up Your Remote Invokes

Published 24 June 08 01:40 PM | jacobl 

The WebImageViewer is a very powerful web control that we offer to our customers. It does a lot of work for you behind the scenes to make the experience as application-like as possible. It even takes that a step further with the RemoteInvoke method and RemoteInvoked event by providing customers with the ability to make server-side function calls in an AJAXy way while not requiring that they know anything about how it works behind the scenes.

Wait Your Turn!

RemoteInvoking with the WebImageViewer makes an assumption that much of AJAX-based web techniques make: you must serialize your requests or they will step on each other. (Serialize in the sense that they are not parallel... not turn into a bytified version of an object). This can be a little annoying if you don't know what you are doing or if your user works faster than you expected. You must make the appropriate accommodations such as locking up the UI while background processing is happening.

The Other Approach

Locking up the UI might not seem like the best option. You might want to allow your users to send multiple requests to the server and just have them be processed at will. This is where this little piece of code comes in. It wraps the WebImageViewer's RemoteInvoke system in a queuing service. You simply create a new Remoter JavaScript object by passing in the WebImageViewer object and you're off to the races. You'll have to make a few minor modifications to your RemoteInvoke calls and RemoteInvoked event handler assignments, but it's all well worth it.

Here's what it looks like to make a RemoteInvoke call with the WebImageViewer:

WebImageViewer1.RemoteInvoked = OnRemoteInvoked;
WebImageViewer1.RemoteInvoke("RemoteMethod", new Array("array", "of", "args"));

function OnRemoteInvoked()
WebImageViewer1.RemoteInvoked = function() {};
// any post-request processing goes here

Here's what it looks like when using the Remoter class:

var remoter = new Remoter("WebImageViewer1");
remoter.RemoteInvoke("RemoteMethod", new Array("array", "of", "args"), OnRemoteInvoked);

function OnRemoteInvoked()
// any post-request processing goes here

What's for free?

You get something out of this for free that you might not expect. In addition to having all of your remote requests queued up so that they automatically don't stomp on each other, you also get the benefit of not having to reset your RemoteInvoked event handler. You're forced to set the RemoteInvoked function each time, and it is always set to an empty function if you don't.

With this handy little utility, you can do stuff like this:

var remoter = new Remoter(WebImageViewer1);

remoter.RemoteInvoke("RemoteMethod1", new Array(), OnRemoteInvoked1);

remoter.RemoteInvoke("RemoteMethod2", new Array(), OnRemoteInvoked2);

remoter.RemoteInvoke("RemoteMethod3", new Array(), OnRemoteInvoked3);

As each request is sent to the server and a response is received back, the next request will fire.

client ----> RemoteMethod1 -----> server
client <---- OnRemoteInvoked1 <----server

client ----> RemoteMethod2 -----> server
client <---- OnRemoteInvoked2 <----server

client ----> RemoteMethod3 -----> server
client <---- OnRemoteInvoked3 <----server

How do I use it?

After you download it using the link below, include it in your project. Add the following script tag to include it in your aspx page.

<script type="text/javascript" language="javascript" src="path/to/Remoter.js"></script>

That line must go in the same <form> that your WebImageViewer or WebAnnotationViewer is in. Next, you need to add the following line to the function that is called once the WebImageViewer is done loading.

var remoter = new Remoter(WebImageViewer1);

Replace WebImageViewer1 with the id of your WebImageViewer or WebAnnotationViewer. To make sure that this function is called at the right moment, call it with atalaInitClientScript(); like so:

<script type="text/javascript" language="javascript">


function OnPageLoad()

 var remoter =new Remoter(WebImageViewer1);
// other code that you want to call after the WebImageViewer is initialized.



Where do I get it?

Remoter is not part of DotImage, but can be downloaded here and used for free.

If you happen to be a PHP developer, check out my personal blog for information about Remoter's adaptation to PHP. 


# RickM said on June 24, 2008 6:13 PM:

Hey, this is really cool!

# DotNetKicks.com said on June 25, 2008 1:35 AM:

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# Fioricet free shipping. said on June 4, 2010 9:53 PM:

Fioricet phentermine shipping.

Anonymous comments are disabled