How to call long running web services in c#? - c#-3.0

I have one web service method it is taking long time to run. i want to make it asynchronous
and web service client should not wait for web method to complete. How i could implement this on c#.
//Web Method
[WebMethod]
public void StartProcess()
{
//long running method
}
//Web Client
webService.StartProcess();

Generate your service reference or edit it by choosing async option in VS, now the generation process will create two calls and one will be yourMethodAsync that you can call. You can also setup a callback this way.
Also you can use parallel tasks in C# to put a call on a background thread. I prefer to generate the async methods since it is cleaner.
here is a post that will help

Related

GWT: How to run code in the Backend automatically?

I understood that GWT apps are separated into Frontend and Backend code.
In the little example that I wrote the Backend operations (XXXServiceImpl) are alwyas triggered by the Frontend (button pressed, etc.).
Question: Is there a way to run code in the Backend automatically? An example would be some initialization stuff that's not triggered by the Frontend (preferably it would be only executed once, during startup of the web app).
Calls to the server do not have to be triggered by a user. When your web app launches, it can make a call like initialize() to the backend, which will tell your server-side code to run some initialization method once.
If this initialization process is not dependent on a single client instance, you can add a check to see if the initialization has been already done and skip it in this case.
Finally, you can run a simple servlet that you can trigger manually (or using a cron-job, deferred task, etc. - depends on your platform) when you deploy your code. The drawback here is that you have to remember to do it every time a new server instance is started.

Any sample async JAX-RS webhook example

I have a JAX-RS web service.
One of the operations may take a long time so I need to make this an asynchronous REST call and then callback the client once it's complete.
I read about "WebHooks" and wonder is there a sample implementaion I can follow?
http://www.infoq.com/news/2009/07/AsynchronousRest

GWT RPC basics control flow explanation

I am new to GWT and am able to work around with GWT RPC but have problem in understanding how the control flow takes place internally. How it gets translated to AJAX?
Can we use new() instead of GWT.create(someService.class) to make an RPC call?
Why does Google not just use Async version instead of creating 2 interfaces?
What happens internally when we use
TaskService Async = GWT.create(TaskService.class);
I have read that it chooses the browser specific hashname.js file but am not understanding the complete control flow. Also How is the Callback Object used.
Can someone explain the control flow by pointing out the essentials?
UPDATE : #Thomas Broyer, Everything I understood... Just confirming that in case GWT.create() there is a .rpc file in the client side which helps in the deferred(late/runtime) binding. Is that correct?
GWT.create() will in this case call a GWT generator; it'll generate a class implementing the Async interface (and that's why you only have to declare an interface and you never implement it yourself).
See RPC Plumbing Diagram.
Using a generator (or selecting a specific implementation, but in the case of GWT-RPC, a generator is used) is called deferred binding.
So, no, you cannot use new.
As to why there are 2 interfaces, this is so that GWT can check that your server-side code (synchronous) is consistent with your client-side code (async). The reason you call GWT.create on the synchronous interface and it returns an implementation of the async one is legacy. I bet they wouldn't do it that way, were they to re-implement GWT-RPC from scratch.
The generated class will be responsible of serializing the call (method name and arguments) and make an AJAX request (using a RequestBuilder); and then deserialize the response (either of the type declared, or an exception)
Because calls are asynchronous, the callback is used to, well, call your code back when the server responds, after deserialization takes place (so either calling onSuccess with the decoded object, or onFailure with the decoded exception).
See Getting Used to Asynchronous Calls

Gwt need to create Async and Sync interfaces for RPC request

what is the need to create Async and Sync interface in client package and its impl class in Server package when need to impelement RPC in GWT. What is the need to create Sync as well as Async interface in GWT for successful RPC.
In a nutshell: Async is needed for client side, Sync is needed for server side.
All RPC (XmlHttpRequest) calls in Javascript are asynchronous - when network call is finished, your code is called with result.
So on client side with GWT RPC you must provide an Async interface (and implementation of it) in order to be called when results are available.
You must also provide related Sync interface which is implemented on server side.
There is a contract on how Async and Sync interface must be written: http://code.google.com/webtoolkit/doc/latest/tutorial/RPC.html
well I assume that you know that any JS in browser is kind of synchronous event driven.
To responce to the RPC you need a callback.
So when writing Java code you need to pass the callback object to a call.
but the server side is a simple method call with return type that should match the parameter of the callback. Right?
So here you get 2 interfaces that all together give you full type safety at compile time. and allows it all work smooth as it does.

Threading in GWT (Client)

From what I understand, the entire client side of a GWT application is converted to Javascript when you build, therefore I suppose this question is related to both Javascript and the possibilities that GWT offers.
I have a couple of dozen processes that will need to be initiated in my GWT application, each process will then continuously make calls to a server. Does GWT support threading? Does the GWT client side support threading?
EDIT:
This link states:
No JavaScript knowledge required If you’re just a user of the framework,
which I am for the matter of discussion, you do not need to know JavaScript
in order to write dynamic content, be it client-side such as rolling frames,
docking panels or scheduled “multi-threading” tasks, or server-side calls
using XMLHttpRequests (aka AJAX).
or scheduled “multi-threading” tasks, what does this mean?
JavaScript doesn't support multithreading. However, GWT has a class to 'simulate' threading, which is not real multithreading, but in most cases does what you need: com.google.gwt.core.client.Scheduler.ScheduledCommand. The technique is based on the timer class, which executes a method after the given time elapses.
For example, when placing the following code in you own code, the scheduleDeferred method will return directly and your code continues after the command, while the execute() method is executed using the timer:
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
public void execute() {
.. code here is executed using the timer technique.
}
});
You can create a repeating command RepeatingCommand, which can be used to run the command more than once. Start it with Scheduler.get().scheduleIncremental() that will execute the command until the execute method returns false. You can use this to split tasks into sub tasks to get better 'threading' behavior. The Scheduler supports some additional methods to start a scheduled command differently. See the JavaDoc for more details.
Edited and updated with new GWT class instead of the deprecated DeferredCommand.
There is work on Web Workers as part of HTML5 that is implemented in a number of browsers, but not on all (most notably internet explorer). You could use these features where available, but what you should do is look at the javascript programming model.
Javascript generally works asynchronously. Requests are fired off and at some point their answers are received as an event. You can have a large number of pending requests at the same time. This will require a bit of a redesign of your system though.
New way is to use a Scheduler
JavaScript doesn't support multithreading, so whatever GWT does, multithreading has to be done solely on the server side, because GWT can only use features that are already available on the client side.