Return to the client from within a service call, but continue executing the workflow? - workflow-foundation-4

I have a WF 4 service. I have the following sequence:
Receive activity
Some Other activities
SendReply
Other Activities
I have an asp.net calling this service.
Why does this client has to wait for all steps to complete?
I want that when step 3 is completed, the reply is sent to the client and the client can continue on its own.
any assistance would be greatly appreciated.

The response is ready to send but due to the async nature of WF4 it isn't actually send directly. You can either persist the workflow, using the PersistBeforeSend, or add a small sub second delay using a Delay activity.

When the Workflow hits the SendReply block it should send the reply at that point and allow the client to continue on. You could test that by putting a delay in of a couple of minutes at Step 4.
Is it possible that the steps after the SendReply are completing so quickly that it just looks like the Workflow is running those steps before sending the reply?

Related

Apache Camel Architecture

I am working on prototyping a new web service for my company and we are considering Apache Camel as our integration framework. Here is a quick run-down of the high-level architecture:
-IBM Websphere MQ as the queuing solution
1) we receive http request
2) asynchronously persist this request
3a) do some processing on the request
3b) send to another tier for further processing
4) asynchronously update the request record in DB
5) respond to caller
What I want to do is:
When a http request comes in, put it on a queue to be processed and wait n seconds. If the web handler doesn't get a response in n seconds, reply to the caller with a custom message
Once the request is on the processing queue, a camel route is listening to this queue to process. When it pulls a message from queue, put a copy of the request on a different queue to be persisted asynchronously. Do some processing on the request. Then send it to another queue to be further processed and wait for a response. Then put it back on the persist queue to be asynchronously updated.
Then respond to web listener. Then web listener responds to web caller.
I am reading everything I can about Apache Camel and there is a lot of information about there. I might be on a little bit of information overload, and any help on the following concerns would be greatly appreciated:
1)
If the web listeners use an InOut exchange (with the first processing tier) without a replyTo queue defined, it will create a temporary queue for the response. What happens if this request times out? I understand I can set a requestTimeout on the exchange and, if it times out, catch that exception and set a custom message. But, will that temporary queue be killed? Or will they build up over time as requests time out?
2)
When it comes to scaling the processing tiers (adding more instances of those same routes on different machines), is it customary that if the instance that picks up the response (using a fixed reply to queue) is different than the instance that picked up the request, all the information about the original request is inside the message, so there is no need to share data across instances (unless of course there is data that is shared, like aggregrates and such)?
Any other tips and tricks when building a system like this would be very helpful.
Thanks!
I would say this solution is too complicated and there are too many areas which are hard both in terms of maintenance and also complexity. There is too much many steps mixing async and sync communication.
Why not simply the solution to the following steps:
Synchronously http request
Put message on MQ with reply to header
Message is picked up and sent to backend
If reply is not received within a given time transaction is terminated.
The reply to queue is removed
Requestor is notified.

creating a one on one chat inside an asp.net website

i would like to create a facebook like one on one chat within an asp.net website, but i cant figure out the mechanism or how it would work.
so far i only have a database table for it designed like this:
id | user1 | user2 | datetime | message
how do i get started, thanks.
I'd consider utilising Signal R for this type of feature - see this guide on implementing a chat feature with signal r - should remove a lot of pain from the development process http://geekswithblogs.net/jeroenb/archive/2011/12/14/signalr-starter-application.aspx
take a look at this:
Simple Chat Application in ASP.NET
The most efficient method to build a chat in asp.net is to use a IHttpAsyncHandler and ajax requests.
Here is a completely working project that implements this, along with ajax.
An async request allows you to delay the response of a request till an external event occurs.
A user makes a call to this handler and waits till someone sends him a message.
Messages are delivered as soon as you send them to a user.
On receiving a message the client makes another request and waits for the next message.
This is a lot more efficient than polling the site to check if messages have arrived.
Using the async handler also ensures that no asp.net threads are wasted waiting while a user waits for messages to come.
This ensures that you chat can scale well even as the number of users of the site goes up.

WF4 SendReply to Receive in another activity

I'm new to WF4 and was wondering if it was possible to send a reply to a receive activity defined in another workflow?
Once my WCF service receives a request I'm performing an operation in another activity and under certain conditions I want to send a reply to the request from this activity and then pause the workflow for further input. Is it possible to do this?
Thanks!
No that won't work. The Receive and the SendReply need to be linked to each other using an activity correlation handle.
What you can do however is use duplex communications where the second workflow sends a SOAP message to an endpoint with an address passed to it in the first message. Technically these are two separate requests and not related so there are no restrictions.

Request timeout issue

I have web application with WCF service. That service contains method that implements message notification. The problem is that with big number of users it takes too much time and throws request timeout exception. What is the best way to solve this problem. Increasing time for request is not available, user won't wait more than minute. Maybe multi-threading or async invocation of notification method will help? Or is there better solution?
If your notification method is not essential for the request to be serviced effectively, then move it to another thread.
As an architectural point you may consider moving all notifications to their own service, the API of which can then be consumed asynchronously.
See here for how.

How to send status information from a Web service while is being executed?

I'm new to web development so I'm not sure what's the best option for the problem that I'm having.
Basically I have a web application that calls a web service for processing some data.
This process may take a long time (hours) and I would to know if there is an easy way to send some status information to the client from time to time.
Right now, the client makes the request from the browser and it just waits there until it finishes.
How can I send some information from the web service? I would like to send a percentage and some additional text specifying what is being done.
Thanks
WCF services can be marked as [OneWay] so that they don't return a response.
or, you could have the service kick off the process in an async manner and then just return to the client that the process has/or hasn't kicked off.
Then, the client can poll another method as the other user has suggested.
If you process takes hours you definitely can't use a sync service because you'll hit your execution timeout or rather the connection timeout for the client.
Maybe you can poll another method for status?
If I were you, I would make the original request asynchronous, as in instead of waiting for the response, it just "starts" the task and returns immediately. Then I would have a separate method on your web service that the app can poll periodically to get the status of the job. once it completes, it can display the data like the original request was doing.
if you want to do it synchronously, you can turn off Response.Buffer and write directly to the response.

Resources