Sync on web service and browser calls

I have an HttpHandler that requests 3 web services in a single request and stores the results in a single cookie.

Do you think the results are colliding. Here's how:

The process is as follows: when I request service 1 and expect the result, the cookie storing the results does not exist yet, then the result comes from service 2 and volia, creates a cookie, saves the result, and then the response comes back from service 1 and overwrites this cookie that shouldn't be.

what I like is the queue for these requests.

Should I do this client side through javascript? if so, how? :)

or do it server side?

therefore I do not want asynchronous calls. is not it?

here is the code:

if(service1.isEnabled){ invokeService1(); } if(service2.isEnabled){ invokeService2(); } if(service3.isEnabled){ invokeService3(); } invokeService1(){ callToService1(); // response comes to another HttpHandler, which is a redirect from the service } invokeService2(){ callToService2(); // response comes to another HttpHandler, which is a redirect from the service } invokeService3(){ callToService3(); // response comes to another HttpHandler, which is a redirect from the service } 

when responses arrive at the HttpHandler, it comes with a request.

then on this HttpHandler:

 HttpCookie cookie = request.Cookie.Get(MYCookie) ?? new HttpCookie(MYCookie); if(request.Params["foo"]){ //set cookie content } if(request.Params["Bar"].isNotNullOrEmpty()){ //set cookie content } 

this is how i installed it. I think the way to create a cookie is the problem.

+4
source share
2 answers

Can you serialize queries and make the client indirectly?

eg:

First customer request

  GET /handler.ashx HTTP / 1.1
 ....

The server will ignore that there is no cookie in the request. Thus, it is assumed that this is a new compound. Redirected server response:

  HTTP / 1.1 302 Moved
 Location: http://server.com/handler.ashx?executeService1

The second request from the client

Now the client sends the request to the .ashx handler? executeService1

The handler receives this request and requests WebService1. And puts the cookie in the response (with a different redirect)

  HTTP / 1.1 302 Moved
 Location: http://server.com/handler.ashx?executeService2
 set-cookie: value

Do you understand the idea?

The advantage is that the server is shaking hands with the client. SErver knows how many times you need to call web services and use cookies to do this.

Another option you propose to do on the client side is using javascript and AJAX with XML payload. When the webservice calls are completed, you can call the server with the result of the service calls, and the server can set a cookie on the client.

0
source

No, things get a lot simpler if you rely on asynchronous calls, so you need to provide callback functions for the invokeService and callService methods, and then continue with the callback.

Try the following:

 var cookieData = {}; var callService = function(service, onCalledService) { // TODO #1: contact the server to get the cookie data // on server callback: // TODO #2: append the retrieved data to cookieData // and still inside the server callback do: onCalledService(); }; var invokeService = function(service, onInvokedService) { if (service.isEnabled) { callService(service, function() { onInvokedService(); }); } else { onInvokedService(); } }; invokeService(service1, function () { invokeService(service2, function () { invokeService(service3, function () { // cookieData now has all the data you need, so: // TODO #3: set the cookie content }); }); }); 

Here's what you should get:

 1. invokeService(service1, ...) will check if service1 is enabled 1.1. if service1 is enabled 1.1.1. callService(service1, ...) 1.1.2. append the retrieved data to cookieData 1.1.3. call the callback (ie go to 2.) 1.2. if service1 is not enabled 1.2.1. call the callback (ie go to 2.) 2. invokeService(service2, ...) will check if service2 is enabled 2.1. if service2 is enabled 2.1.1. callService(service2, ...) 2.1.2. append the retrieved data to cookieData 2.1.3. call the callback (ie go to 3.) 2.2. if service2 is not enabled 2.2.1. call the callback (ie go to 3.) 3. invokeService(service3, ...) will check if service3 is enabled 3.1. if service3 is enabled 3.1.1. callService(service3, ...) 3.1.2. append the retrieved data to cookieData 3.1.3. call the callback (ie go to 4.) 3.2. if service3 is not enabled 3.2.1. call the callback (ie go to 4.) 4. set the cookie content 
+1
source

All Articles