tags:

views:

465

answers:

2

If I have a client app sending requests to my web service, one after another, will the web service be able to handle each request made and not override previous request because of a new request made? I want all requests to be handled and not replaced for another. Will I be able to do this with the multiple requests all coming from the same client

A: 

The answer depends on your architecture.

For example, if the server is multi-threaded, and the business logic part is stateless, then on the server the requests won't override, as each thread will call a function and return the result.

On the client side, your best bet is to have each request sent from a different thread, so that that thread blocks until it gets its response, then the processing can go on fine.

If you have a different design, please describe it.

UPDATE: Based on the new info here is something you may want to look at: http://weblogs.java.net/blog/2006/02/01/can-i-call-you-back-asynchronous-web-services

I am curious how, or if, you are doing asynchronous webservice calls. Generally webservices seem to block, but if you are making these calls so fast then I can only assume asynchronicity.

So, the webservice can store the answers on the server-side, so there is a stateful class that stores results in a dictionary, by IP address. The client then polls for answers, so, ideally, if you send a request, you should be able to get back an array of answers as a response. If you have sent all the requests and are still waiting for more responses, then poll. You should be able, again, to get an array of answers, to cut down on wasted bandwidth.

The better approach is to have your client also be a server, so that you send the request, with the IP address:port for the callback, so the server would make a oneway response to the client. But, this is more complicated, but it cuts down on wasting bandwidth.

Update 2: This is being done without checking it, so there is probably errors:

@WebMethod
public ResponseModel[] AnswerQuestion(QuestionModel[] question) {
// Get the IP address of the client
  AnswerController ac = new AnswerController(question, ipaddress);
  return mypackage.myclass.StaticAnswers.GetAnswers(ipaddress);
  // return an array
}

@WebMethod
public ResponseModel[] GetAnswers() {
   return mypackage.myclass.StaticAnswers.GetAnswers(ipaddress);
}

OK, this should give a rough idea.

There is no assumptions in AnswerController. It should know everything it needs to do the job, as it will be stateless, so, it refers to no global variables that can change, only const and perhaps static variables.

The StaticAnswers class is static and just stores answers, with the lookup being ipaddress, for speed.

It will return the answers in an appropriate array.

When you have sent the last question then just call GetAnswers until you have gotten back everything. You may need to keep track of how many have been sent, and how many have been received, on the client side.

This isn't ideal, and is a very rough sketch, but hopefully it will give you something to work with.

James Black
Thank you. Here's a little example.Client asks web service: what is "1+1?"Then before the web service can even finish and respond to that request, client asks web service: what is "3+4" Basically the same client asks web service about a hundred questions(requests) at once. I want the web service to handle them all despite the fact that these are requests made from the same client.
brandon
Easier said: multiple requests are sent from the same client at once and hopes web service can handle them all.
brandon
The webservice server should be multithreaded. What framework are you using for the server? On the server-side it is important that the webservice endpoint gets the request, passes the question to a stateless class for processing, and that processing can put it into the static (stateful) answer class.
James Black
I'm using .NET Framework
brandon
I just don't want the web service to get a request from my client then get another request right after that one was made and say "Oh so you want me to forget about the first request and handle this new request instead?" I want it to say "Oh, another request I'll handle this too and however more you have for me"
brandon
@Brandon - .asmx files, WCF, the .NET 2.0 @Webservice annotations, perhaps Spring.NET webservices? Which method are you using? Is this IIS or some other webserver?
James Black
asmx files possibly. I'm having this web service built to mimic an application I made in VB.NET but because I'm lacking in knowledge to actually write the code, another person is going to do it for me so I don't know what they will end up doing.
brandon
@Brandon - I showed what is probably the simpler solution, but if you don't have control over the server then your best bet is to know the question you send, and have the question/answer both returned, so you can match up questions with answers.
James Black
You've been very helpful thank you very much.
brandon
A: 

I have no idea why the othe answer is so long to what is essentially a simple question about the basics but the answer is yes.

Each request in independent of others, unless you specifically program some sort of crossover into the server (e.g. a static cross-thread list used by every request or a more complex structure).

It is easier to encounter crossover on the client side, if using an asynchronous pattern that gives results via events - you need to make sure you got the result to the correct request (generally done by providing some token as the "custom state" variable, which you can use to determine the original request in the response handler).

Sander