Answered by:
Webservice to set global variable once

Question
-
I have a webservice that we need to write that is basically called by the client in a loop on their side, to insert multiple records. Since the records are all based on a record id, there is no need to send the recordid for each record being inserted once you have started the process, the first step in the process is to provide us a list of columns you will be updating, one of the values is the recordid, we then do our logic and create the insert/update statement to use that list of columns.
Then right after, you begin to send the data for those columns, once you have provided recordid, we want to store it and reuse it until a new recordid is provided..
What would be the best solution to accomplish this within the webservice?
thank
- Moved by Mike Feng Thursday, February 14, 2013 4:29 AM
Monday, February 11, 2013 8:16 PM
Answers
-
It would generally be a lot easier and faster to generate the entire array on the client side and send it at once. Each Webclient call has a rather big overhead. Plus depending on how bad the conection/network is, it might take time before the client has the sending finsihed. Time during wich the UI will either not react or (if you use async calls) during wich concurrency errors can occur.
One thing you will need to do is clearly identify wich user is just dropping an entry. After all more then one can use this functionality at once. So you need some session identifier.
The approach I once used for a small Chatclient is to make a public, serialisable "SessionHandle" class and write a "register" Method that gives each client a unique SesionHandle instance. The clients job is to take it and send it along each time they enter something (in addition to the data they send), without ever changing it (there is no way to force them to not modify it). So the server can clearly identify wich user is just dropping information.
I am not certain if there was any sort of global value (that at least sticks around as long as the service runs). But it would propably need to be a global static varriable. Saving it to soem otehr sources (Database server, textfile) might be easier.
- Edited by Christopher84 Monday, February 11, 2013 8:59 PM
- Proposed as answer by Mike Feng Wednesday, February 13, 2013 2:43 PM
- Marked as answer by Haixia_Xie Monday, February 18, 2013 2:31 AM
Monday, February 11, 2013 8:58 PM -
Hi,
As Christopher said try to work in bigger chunk. Note also that it might just solve this issue (as you'll send the id all along with all the info needed for processing this particular id and possibly others).
My understanding is that you have currently ONE operation that spans MULTIPLE calls which is likely a bad idea anyway (you send each value as a separate call one of which being the id that you need then to keep ? Instead send at least all values for a single record in one go to keep this as a single call (and you could allow to send several records in one go as well but never ever allow just a part of a record in one go and then having to send a single record in multiple calls).
NEVER use a global variable (what happens if multiple clients are calling the webservice ?) at worst keep a value per session and at best just design your service so that you never have to store something server side...
Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".
- Edited by Patrice ScribeMVP Tuesday, February 12, 2013 6:37 PM
- Proposed as answer by Mike Feng Wednesday, February 13, 2013 2:44 PM
- Marked as answer by Haixia_Xie Monday, February 18, 2013 2:31 AM
Tuesday, February 12, 2013 6:36 PM
All replies
-
It would generally be a lot easier and faster to generate the entire array on the client side and send it at once. Each Webclient call has a rather big overhead. Plus depending on how bad the conection/network is, it might take time before the client has the sending finsihed. Time during wich the UI will either not react or (if you use async calls) during wich concurrency errors can occur.
One thing you will need to do is clearly identify wich user is just dropping an entry. After all more then one can use this functionality at once. So you need some session identifier.
The approach I once used for a small Chatclient is to make a public, serialisable "SessionHandle" class and write a "register" Method that gives each client a unique SesionHandle instance. The clients job is to take it and send it along each time they enter something (in addition to the data they send), without ever changing it (there is no way to force them to not modify it). So the server can clearly identify wich user is just dropping information.
I am not certain if there was any sort of global value (that at least sticks around as long as the service runs). But it would propably need to be a global static varriable. Saving it to soem otehr sources (Database server, textfile) might be easier.
- Edited by Christopher84 Monday, February 11, 2013 8:59 PM
- Proposed as answer by Mike Feng Wednesday, February 13, 2013 2:43 PM
- Marked as answer by Haixia_Xie Monday, February 18, 2013 2:31 AM
Monday, February 11, 2013 8:58 PM -
Hi,
As Christopher said try to work in bigger chunk. Note also that it might just solve this issue (as you'll send the id all along with all the info needed for processing this particular id and possibly others).
My understanding is that you have currently ONE operation that spans MULTIPLE calls which is likely a bad idea anyway (you send each value as a separate call one of which being the id that you need then to keep ? Instead send at least all values for a single record in one go to keep this as a single call (and you could allow to send several records in one go as well but never ever allow just a part of a record in one go and then having to send a single record in multiple calls).
NEVER use a global variable (what happens if multiple clients are calling the webservice ?) at worst keep a value per session and at best just design your service so that you never have to store something server side...
Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".
- Edited by Patrice ScribeMVP Tuesday, February 12, 2013 6:37 PM
- Proposed as answer by Mike Feng Wednesday, February 13, 2013 2:44 PM
- Marked as answer by Haixia_Xie Monday, February 18, 2013 2:31 AM
Tuesday, February 12, 2013 6:36 PM