Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Services > Web Service Requests Processed Out of Order

Reply
Thread Tools

Web Service Requests Processed Out of Order

 
 
mgdev
Guest
Posts: n/a
 
      02-13-2007
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?
 
Reply With Quote
 
 
 
 
John Saunders
Guest
Posts: n/a
 
      02-13-2007
"mgdev" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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


 
Reply With Quote
 
 
 
 
mgdev
Guest
Posts: n/a
 
      02-15-2007
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.

 
Reply With Quote
 
John Saunders
Guest
Posts: n/a
 
      02-16-2007
"mgdev" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> 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


 
Reply With Quote
 
mgdev
Guest
Posts: n/a
 
      02-16-2007
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.
 
Reply With Quote
 
John Saunders
Guest
Posts: n/a
 
      02-17-2007
"mgdev" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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


 
Reply With Quote
 
mgdev
Guest
Posts: n/a
 
      02-19-2007
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.
 
Reply With Quote
 
John Saunders
Guest
Posts: n/a
 
      02-19-2007
"mgdev" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Does timer in Web Service Global.asax block my Web Service from processing web-site requests? Leo Violette ASP .Net Web Services 0 04-17-2009 12:39 AM
Bug? OutputCache directive processed when commented out Amil Hanish ASP .Net 1 08-25-2006 05:29 AM
order of usercontrols processed by events of page Gokhan Akca ASP .Net Web Controls 1 05-30-2005 02:07 PM
web requests and mobile requests Fernando Arámburu ASP .Net 1 04-08-2005 07:13 PM
How can I reset my directory to view digital images in the order taken, not processed? M. Souris Digital Photography 3 08-11-2003 07:14 PM



Advertisments