WCF for Queue-ing processing intensive tasks

Posted on 2009-04-19
Last Modified: 2013-11-15
I am working with an ASP.NET site that must interact with a vendor's XML-based API using HTTP Request / Response pairs.  

There is a strong possibility that the site will perform poorly under a heavy traffic load due to the overhead involved in making 2 HTTPRequest calls for each user submission.

In order to deal with this problem, I would like to handle the requests asynchronously by queuing the requests and just displaying a message that says "Your request has been received.  You will receive an email when your account has been created in the database.  Thanks...".

I am struggling with the stateless-model of programming.   In a console application, I would create a separate Thread that processes Commands when the Count of the Queue is > 0.   Initial experiments using the Application object (and serialization) have failed.

After a lot of reading, I think that I may need to do this with WCF.   Can someone confirm that this situation is a good match for WCF and give me some direction as to which options I should select in order to do this in the simplest manner possible?

My service should only be callable by one aspx page - how does this affect the options I should select in creating the service?

Can a WCF application maintain the state of the queue?   Does this mean that I need to run it as a windows service?  Or can I still run it under IIS?

Some of my reading has made me wonder if I should use WCF with MSMQ.   Is this necessary?   I just need a basic command queue and I definitely don't want the client to have to install MSMQ to be able to use the app.

Would there be any advantage to creating this as a web service instead of a WCF app?

This is my first .NET application.   I am reading Pro C# 2008 and the .NET 3.5 Platform, Fourth Edition and the O'Reily WCF book.   Any other links / resources would be appreciated.
Question by:trey_carroll
    LVL 25

    Assisted Solution

    You can use web service and call its method asynchronous. Below is the URL which gives you more detail on how to create it. IIS is not going to be help up like synchronous call and hence you will be getting good performace. Please do load test after implementing Asynchronous way to see it gives expected performance.

    If you lot of methods to expose as said above and if the requirement is going to change often like e.g. if you are going to access your method in HTTP or TCP in future . you can go for WCF.

    You don't need to install MSMQ in the client side and it is going to queue in server so that u can read whenever you want and process them. You can use WIndows service to or you can use IIS also to host your service.

    Accepted Solution

    The web service did not seem to offer a clear path to what I needed to do.   All of the mentions of maintaining state referred to the state of a particular user's session - not for an instance variable such as a queue that would have scope for multiple users' requests.  

    The code examples that I did manage to locate for spawning separate threads from a web service were FAR inside of the realm of experts only - with much code that was hardly recognizable as C#.

    The answer to the this problem for me turned out to be:

    Install msmq.   Enqueue requests.   Create a Windows Service that runs on a timer to dequeue and process requests.  Use transactions to make sure that you don't lose any.

    If you are attempting the same- a word of advice.   Create a separate console application that mirrors the code from the service for debugging purposes.   You cannot run the sevice code in the VS debugger and once you install and start it you lose communication with it.   The console "mirror" of the code will save you MUCH time and frustration.

    Author Comment

    Found the Web Service would not work.   Posted alternative solution.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    I use more than 1 computer in my office for various reasons. Multiple keyboards and mice take up more than just extra space, they make working a little more complicated. Using one mouse and keyboard for all of my computers makes life easier. This co…
    This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
    Video by: Kyle
    After watching the Introduction to GIMP and additional tools to use in GIMP we are shown how to utilize multiple tools to create a 3D effect image.
    Introduction to GIMP:  GNU Image Manipulation Program. It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now