NServiceBus is blocking when hosted in ASP.NET web application - asp.net

I created a simple web application where a search form is filled out, submit
button clicked, and a message is sent with the search parameters via
nServiceBus. I also have a handler in the same project that picks up the message
(from the same queue). For some reason, the web server process blocks until
after the message is picked up, is there any reason for this? I set a breakpoint
in the message handler and it breaks before the request finishes... locking the
browser until I allow the code to continue. I would expect control to return to
the browser regardless of when the handler gets fired...
Thanks,
D.Niemeyer

Are you using .RegisterWebCallback() in your code, as that is what is responsible for preventing ASP.NET to complete the HTTP call?

This was answered in the nServiceBus forum. This is a phenomenon caused by having the debugger attached, which stops all threads if a breakpoint is hit before the response is returned. Placing a sleep in the handler demonstrates this.

Related

Async WCF call not always successfully when silverlight app is closing

I have a silverlight app running in a browser as part of an overall ASP.NET website. I'm doing some event logging from it (tracking some UI click events and such).
I have a WCF service set up to create DB log records, and obviously the Silverlight app is calling it asynchronously.
This all works just fine, until I try to fire off a call to the logging service at the tail end of the app life. That is, when the user clicks a certain button, the silverlight calls some javascript on the website to redirects to another page, so the silverlight app closes, and then only sometimes do the last logger calls get through.
I am assuming it has something to do with the shutdown procedure of silverlight, and that it is a timing issue whereby sometimes the WCF channel is still open and the message gets through, and sometimes the channel closes and the logging doesn't occur.
Regardless of whether or not the logging occurs, the callback never fires for this last logger call.
As part of the handler for the last closing click event, the silverlight app calls this:
System.Windows.Browser.HtmlPage.Window.Eval("ViewEmployersPageWithMenu();")
Which, as I understand it, will trigger an exit of the silverlight app as the browser is navigating away from it.
Just before doing this, I fire off a simple logger call to my async wCF service.
I believe silverlight doesn't allow async service calls during its exit handling, is this the case? If there a different way I should be handling this o get that log call out successfully before the app closes?
If the logging is that important and considered an integral part of the application, you could hold off on calling the JavaScript function until the callback of the logging request. It may cause some delay in the execution of the redirect as it is now waiting for the WCF request to round-trip, but perhaps that is preferred to missing the log.
If you can replicate the issue, I would be curious to how Fiddler sees the series of requests (logging request and redirect request) when it works compared to when it does not. That may show that the browser is canceling the log request when it executes the redirect.

asp.net page wait others server side / asynchrone page

I created an asp.net page for waiting ajax. I have one page creating something that takes 30 seconds. On every step I change a session value.
I have another page for ajax, returning the session value for showing the percentage of creation. But, I dont know why, my ajax page awaits the end of the creation of my first page. So I only get the 100% at the end.
Maybe it's because I use VS development server and not IIS server. If this is the problem, can I change settings of the development server for asynchrone execution?
Or is it something else?
WebForms are not ideal for asynchronous operations.
Add SignalR to your project and use a Hub to push status data back to your page to update the current state of the process you are running Asynchronously.
An example of a technique to perform this type of asynchronous notification is covered in my blog post titled "A Guide to using ASP.Net SignalR with RadNotifications"
Don't use ASP.Net session state to do that. It has an implicit reader/writer lock around it, meaning your other call is probably blocking until your process finishes. You can try storing your status in a database or the cache, but it would probably be better to redesign the interaction.

Does ASP.NET Web Forms prevent a double click submission?

I'm working on an ASP.NET 4.0 Web Forms project, after a break of about 5 years, and I'm confused about the submit behaviour.
In the click event of a button, I sleep the thread so that I can click the submit button multiple times.
From what I can tell, ASP.NET is preventing the click event being called more than once. Is this true?
BTW: I've turned off javascript for this test.
"ASP.NET is preventing the click event being called more than once. Is this true?"
No, actually what is happening to you is that your events are blocked by the lock of the session. (What session is on asp.net, is a module on asp.net that can keeps data for each user that visit the site)
So when you make a submit, and the page is running this submit, and then you make a second one before the first one replay, actually the second one is waiting the first to finish and unlock the session.
To make a test and prove that the session is locking your request, turn off the session and try again your test.
relative:
Web app blocked while processing another web app on sharing same session
What perfmon counters are useful for identifying ASP.NET bottlenecks?
Replacing ASP.Net's session entirely
Trying to make Web Method Asynchronous
No, As you are making your main thread sleep it causes the session to get blocked which prevents it from processing any further requests. Hence it gives that effect. If you have an independent task which can be done without web request and response, then you can perform it in separate thread. This will not block your process.

Do you do client-side logging?

How do you capture errors that happen on client side when building RIA apps using Flex and Silverlight? What are the common practices? I have seen some asynch js calls to a web service implemented but would like to know how the community is dealing with it.
First, I use client side logging all of the times.
the way I handle it depends on the entire application.
if I use an AMF gateway then there's a call for an application error, with every error that occurs the server is notified, in the server side a bug is open in BugZilla (this is what we use, you can use any other hook you want).
If I use a web-service based application then there's a web-service call for a client error.
one would say you shouldn't sample the server with every error, I disagree with this comment because an error in the client side is rare, it goes thorough QA before being released to the client so I want to know immediately on every error the client is experiencing.
In Silverlight I like to use a WebClient to log back to a web service somewhere -- you can do this directly in the Silverlight application without calling out to JavaScript.
To catch exceptions that are fired when your code isn't on the stack, you can use the Application.UnhandledException event.
I've used the same approach as Avi Tzurel - you need to know on the server side when an error appeared in the Flex client. If you want to collect more data (all the log messages, warnings) I would use an internal buffer and I will flush it asynchronously.
Anyway, you need to take into consideration if your customers are ok with this approach..maybe you need their agreement before sending the error message to the server.
I basically percolate all errors to the top, and capture them in the unhandled exception. I display a friendly message to the user. However, throughout my application I implement an ILogger interface. This interface can be initialized with various levels and handles any messaging. You can set it up so the user can add an init param to determine whether or not to transmit the errors to a service, and I typically have the logger write the messages with Debug.WriteLine if the debugger is attached to make it very easy to trace issues in debug mode.
In Silverlight you may want to consider the Logging and Exception Handling Application Blocks from the Silverlight Integration Pack for Enterprise Library.

ASP.NET, asynchronous call to another page, return response immediately

The problem is as follows:
An external server sends incoming SMS messages converted to HTTP requests into my sometimes very time-consuming .aspx page. If no response is returned to the external server in 20 seconds, this is considered as an timeout and the same message is sent to my aspx page again (and maybe again....)
The optimal solution for me would be that the aspx page reads the incoming message (as an HTTP request to the aspx page), starts the processing of the message in another thread, and immediately renders response back to the external server. The external server has no interest in other stuff than the HTTP status (normally 200). When the processing of the message is completed this results in an entry into the log file of the application.
The processing of the message is done by making another web request to an aspx page, and I have tried to use the BeginGetResponse method for the web request, and have created a handler for handling of the completed web request to the processing page. The problem is that the handler seems to not be called, most likely because the aspx page's lifecycle is ended before the asynchrounous web request is completed.
Has anyone any good solution for this problem? I have also looked at the async page model, but this also seems to not be a solution for me because the response should be returned to the external server before the processing of the message is completed.
Regards, Eivind
I'd be very wary of using threads in ASP.Net in this manner. Using them to take advantage of multiple cores is one thing. Using them to set up some kind of concurrent response technique seems like a recipe for disaster. Especially when there is a far more elegant solution.
Your ASP.Net application should merely take the message and toss it in a database and send the success reply. It's job is done. The job of delivering the message should be handled by some kind of service or daemon. Windows Services are kind of a pain to build and maintain so perhaps just a scheduled task that runs every 30 seconds or so checking for queued messages in the DB would suit your purposes just fine.
I've seen a lot of people try to use threads in ASP.Net when they really should just be creating a background service. The results are never as reliable as you would hope.
Async page model is definitely not the solution. Have you tried using the unload event to do EndRequest? I really don't know if that would work but it is worth a try. The most robust way is to use Windows Service to run the async request.

Resources