Web Service Requests Processed Out of Order

Discussion in 'ASP .Net Web Services' started by mgdev, Feb 13, 2007.

  1. mgdev

    mgdev Guest

    I've got a problem where my web service requests are not always processed in
    the same order they are received.

    Both the web service and the windows application are based on the .net
    framework 1.1.

    Background:
    At the server the database is designed with a parent/child relationship.
    The parent is a list of switches (switch A, B, C, ...) and the children are
    the transactions for when an [on] or [off] command has been received. To
    improve query speed I've included a column called [transUID] in the parent
    table to store the [UID] of the newest child record. So when an [on] or
    [off] command is received a new record is placed in the child table and an
    update is made to the parent table to indicate the [UID] of the new child
    record.

    The client application is designed to send requests to the web service to
    turn a switch [on] or [off]. For the most part this works normally.
    However, if the client sends two or more requests quickly (less than a couple
    of seconds in between) the server will sometimes process the requests out of
    order.

    For example: Lets start with the switch being currently set to [off]. The
    [transUID] for the switch is pointing to the last record in the child table
    that represents a status of [off]. Then the client quickly sends an [on]
    request imediately followed by an [off] request (this is a toggle button
    programmed to switch between [on] and [off]). Although the database may show
    the exact same date and time for the two records, the [transUID] should show
    the [UID] of the last transactional record. Unfortunately, this is not
    always the case. Sometimes the second request will get processed first.
    Then in my history I will see the transactions going from [on] to [on] to
    [off]. And the [transUID] is no longer pointing to the correct transaction
    and the data is now inaccurate.

    Any suggestions?
    mgdev, Feb 13, 2007
    #1
    1. Advertising

  2. "mgdev" <> wrote in message
    news:...
    > I've got a problem where my web service requests are not always processed
    > in
    > the same order they are received.


    Why does this surprise you? Did you ever see a guarantee that requests would
    be processed in order?

    If the order of several requests is important, then you should turn them
    into a single request, which can process its pieces in whatever order it
    likes:

    Before:

    [WebMethod]
    public void PartOne(int a)
    {
    }

    [WebMethod]
    public void PartTwo(int b)
    {
    }

    [WebMethod]
    public void PartThree(int c)
    {
    }

    After:

    [WebMethod]
    public void AllThreeInOrder(int a, int b, int c)
    {
    PartOne(a);
    PartTwo(b);
    PartThree(c);
    }

    private void PartOne(int a)
    {
    }

    private void PartTwo(int b)
    {
    }

    private void PartThree(int c)
    {
    }

    John
    John Saunders, Feb 13, 2007
    #2
    1. Advertising

  3. mgdev

    mgdev Guest

    You're right. I have never seen a guarantee that anything should work as
    expected. But I would like to understand the problem so I can at least build
    a work around.

    Unfortunately, your solution doesn't solve my situation.

    The issue is not that a user calling three different functions. The issue
    is that the same function is being called more than once.

    <WebMethod>
    Public Sub SwitchStatus(SwitchID as Integer, Status As Boolean)
    If Status = True Then
    "Turn the switch on"
    Else
    "Turn the switch off"
    End If
    End Sub

    This function is normally called once or twice an hour per switch (Turn the
    switch on or turn the switch off). But when a quick on and off is sent (like
    someone clicking the button twice in the same second), the web service will
    sometimes process the off request first. Then instead of the switch going
    from off to on to off again. It runs the sequence of off to off to on
    leaving it in the wrong position.
    mgdev, Feb 15, 2007
    #3
  4. "mgdev" <> wrote in message
    news:D...
    > You're right. I have never seen a guarantee that anything should work as
    > expected. But I would like to understand the problem so I can at least
    > build
    > a work around.
    >
    > Unfortunately, your solution doesn't solve my situation.
    >
    > The issue is not that a user calling three different functions. The issue
    > is that the same function is being called more than once.
    >
    > <WebMethod>
    > Public Sub SwitchStatus(SwitchID as Integer, Status As Boolean)
    > If Status = True Then
    > "Turn the switch on"
    > Else
    > "Turn the switch off"
    > End If
    > End Sub
    >
    > This function is normally called once or twice an hour per switch (Turn
    > the
    > switch on or turn the switch off). But when a quick on and off is sent
    > (like
    > someone clicking the button twice in the same second), the web service
    > will
    > sometimes process the off request first. Then instead of the switch going
    > from off to on to off again. It runs the sequence of off to off to on
    > leaving it in the wrong position.


    Why not create a web method which toggles the state instead of explicitly
    setting it on or off. That way, if there's a "double-click", it won't matter
    which happens first.

    John
    John Saunders, Feb 16, 2007
    #4
  5. mgdev

    mgdev Guest

    I guess my example is oversimplified. The entire application is much more
    complicated and I'd rather not try to explain the whole thing.

    In reality I have more than two states for my switch. Because of this the
    toggle won't work.

    There are actually about 12 different states that a switch can be in. And
    whether I make them one function call with a parameter or 12 different
    functions the root problem remains the same. The order that the server
    receives the requests is not always the order in which they are processed.
    Even though they are being sent by the same instance of the client
    application in the appropriate consecutive order.
    mgdev, Feb 16, 2007
    #5
  6. "mgdev" <> wrote in message
    news:...
    >I guess my example is oversimplified. The entire application is much more
    > complicated and I'd rather not try to explain the whole thing.
    >
    > In reality I have more than two states for my switch. Because of this the
    > toggle won't work.
    >
    > There are actually about 12 different states that a switch can be in. And
    > whether I make them one function call with a parameter or 12 different
    > functions the root problem remains the same. The order that the server
    > receives the requests is not always the order in which they are processed.
    > Even though they are being sent by the same instance of the client
    > application in the appropriate consecutive order.


    The web services infrastructure makes no guarantees of sequence. If you need
    such a guarantee, you need to impose it yourself. You'll need to have your
    client increment a counter and include it in each message. You'll have to
    have your server keep track of the sequence number for each client instance.
    It will have to queue up requests if they arrive out of order, and will have
    to operate asynchronously (see this month's MSDN magazine for a good
    article).

    Sorry, but you seem to have created an architecture based on incorrect
    assumptions. If you can't re-architect now that you understand that your
    assumptions are false, you'll have to create an infrastructure which makes
    your assumptions true.

    John
    John Saunders, Feb 17, 2007
    #6
  7. mgdev

    mgdev Guest

    OK. I get the issue with the server not processing requests in the order
    they are received/sent. Now I need to explore a couple of questions
    regarding the solution.

    Is there any difference between using a sub vs. a function with the web
    service?

    I'm currently using sub routines in my web service and based on what we've
    talked about the clint calls the routine and continues on without waiting for
    the web service to complete the call. This leads to the client being able to
    send another call without knowing whether or not the first one has completed.

    If I use a function in my web service and coded the client to evaluate the
    return value, would that cause the client code to stop and wait for a
    response before it continues? This would insure that the client can't send a
    second request until the first one has returned it's value.
    mgdev, Feb 19, 2007
    #7
  8. "mgdev" <> wrote in message
    news:...
    > OK. I get the issue with the server not processing requests in the order
    > they are received/sent. Now I need to explore a couple of questions
    > regarding the solution.
    >
    > Is there any difference between using a sub vs. a function with the web
    > service?


    No. They are the same thing.

    > I'm currently using sub routines in my web service and based on what we've
    > talked about the clint calls the routine and continues on without waiting
    > for
    > the web service to complete the call. This leads to the client being able
    > to
    > send another call without knowing whether or not the first one has
    > completed.


    There is no difference between a subroutine and function. The client is
    behaving asynchronously for its own reasons, having nothing to do with the
    server.

    > If I use a function in my web service and coded the client to evaluate the
    > return value, would that cause the client code to stop and wait for a
    > response before it continues? This would insure that the client can't
    > send a
    > second request until the first one has returned it's value.


    There is no difference between a subroutine and a function.

    John
    John Saunders, Feb 19, 2007
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fernando Arámburu

    web requests and mobile requests

    Fernando Arámburu, Apr 8, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    442
    Joerg Jooss
    Apr 8, 2005
  2. Amil Hanish
    Replies:
    1
    Views:
    307
    Juan T. Llibre
    Aug 25, 2006
  3. Gokhan Akca

    order of usercontrols processed by events of page

    Gokhan Akca, May 30, 2005, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    161
    Brock Allen
    May 30, 2005
  4. Michael Fan
    Replies:
    2
    Views:
    132
    Michael Fan
    Jul 16, 2004
  5. Leo Violette
    Replies:
    0
    Views:
    1,016
    Leo Violette
    Apr 17, 2009
Loading...

Share This Page