c# WebService Question

Posted on 2006-04-27
Last Modified: 2008-01-16
I m creating a webservice and which will be accesses by more than one users, might be at the same time. To be more specifc, its a webservice related to money transactions, and as many as 1000 transactions can occur at the same time. And in order to complete the transaction the process has to go thru a number of steps. So, lets say user1 is on step 3, user 2 is on step 2  and user 3 is on the step 4. Will the correct state for all the transcations will be handled by the webservice, like maintaining a session or something once a user is connected to the webservice?

Another question is, suppose in the middle of a transaction, connection is lost, is there any way that the webservice can resume the state if the timeout hasnt been expried?

 Thanx in advance.
Question by:jyotishb
    LVL 12

    Expert Comment

    In a scenario like this you will have to use transaction explicitly, either via COM+ or the Transaction class of the .NET framework.  You will have to start a transaction for each user.  I am not sure how maintaining a session will help you.  You just need to be sure that it is all or nothing.

    If connection is lost the transaction will be rolled back, no change will occur to your data.  If user comes back you start from fresh.  In a scenario like this where monoey is involved ;-) you don't want to hold state
    LVL 9

    Expert Comment

    also, the calling application can call your web service asynchronously, but that won't handle the transaction portion... just another way to call a long running web service.

    Author Comment

    yes, i know, thats why i said timeout.  does HttpsessionState class can help me here???
    LVL 13

    Expert Comment

    asmx web services do not support a lot of the WS-* specs such as reliable message and transactional messaging.
    asmx is also stateless and i would STAY away from session state as the answer to your problem.  there are technologies on the horizon that will do these things out of the box (Indigo/Windows Communcation Foundation). but we are in the now so i would say your architecture should go something like this.

    expose an asmx web service as your endpoint.  make use of MSMQ because it will provide you with the asynchronous/ synchronous transactions, long running trans, if a connection goes down messages will wait until is back up to process.  

    now here comes the harder part.

    you need a service that listens to the MSMQ for messages and constructs whatever "process" you need.  This can be a windows service.

    keep these things in mind.  focus on contract when working with web services.  you should possibly design your xml schema first and then gen wsdl off of that.  keep your services autonomous.  make calls chunky!!!
    if your considering 1000 calls over the wire for a single transaction then i would rethink your approach.  the most expensive part of the call is the serialization so make calls chunky.


    Author Comment

    I m just curious abt this, cos i dont have a very deep idea abt the working of MSMQ. No there wont be 1000 calls for a single transaction. 100 transaction can occur at the same time, which will request some information to the web service.  Dont u think using MSMQ will slow the process, cos if there are say 100 transactions already waiting int he que, the next the person tryng to do the next transaction has to wait till all the others are done. I just want to know, how multiple requests at the same time are handled by webservice. Does the WS creates a session for each request?
    LVL 10

    Accepted Solution

    This is very nice article with source code
    plz read it and hope it will be helpful to use in your progress

    LVL 13

    Assisted Solution

    It depends, MSMQ may even speed up your service significantly.

    Reason: By default will service 25 page requests at a time.  Depending on how long those transactions take to complete the httpruntime will queue the 26th user until a worker thread becomes available to handle the incoming request.  Using MSMQ your simply using web service as an endpoint so you can drop off your message and go.  The client interaction is very quick.

    What things really depend on here is what you consider "a trasaction."  If you consider a transaction to be the execution of 3 stored procs then use the transaction capabilities in and forget msmq.  however if your transaction is a multistep/long running/statefull transaction then msmq is your way to go because a service can listen to the queue and only execute this "transaction" when it sees the information it needs.  Also if the server crashes or boots messages aren't loss.  Your not going to get state management like that in unless you use sql server session management.

    Either way read up on it so you can be aware of this technology.  It is of no $ investment to you.  It even comes on your installation cd of win2k, xp ect.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Article by: Najam
    Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
    This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    754 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

    20 Experts available now in Live!

    Get 1:1 Help Now