Question web service calling strategies

raysefo

Well-known member
Joined
Feb 22, 2019
Messages
237
Programming Experience
10+
Hello,

I have an asp.net web API that calls another web service. This 3rd party web service has a quantity field if I send quantity=2 in my request, it returns 2 items. Max quantity is 10. What if I want to get more than 10 items, let's say 100? 3rd party web service will not change its structure so I wonder what would you do to get more items? I want to hear your suggestions.

Thanks in advance.
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
5,251
Location
Chesapeake, VA
Programming Experience
10+
Sounds like it's their version of throttling. They must have a reason for it. As I recall, the project you are working on is related to game licenses? Perhaps it is their way of enforcing something in your contract with them? Perhaps it is their way of preventing a single client from hogging all the licenses and then reselling them at a higher price?

Anyway, ignoring all the legal or moral reasons as to they may have throttling in place, you could get multiple API keys, and then operate all your servers from behind a masking VPN which randomizes your IP addresses, and then do multiple calls of 10 each, and then pool and hoard all the results together to get your desired 100 items.
 

raysefo

Well-known member
Joined
Feb 22, 2019
Messages
237
Programming Experience
10+
Thank you @Skydiver :) Actually, I am looking for a smart and effective solution in the code base with the current environment that will not put me in trouble in terms of maintainability. The first thing that comes to my mind is to loop

call 3rd party web service every 10 quantity:
for (int i = 0; i < 200; i++)
    {
        if ((i % 10) == 0)
        {
        //call 3rd party
        }
    }
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
5,251
Location
Chesapeake, VA
Programming Experience
10+
In my opinion, a while loop would be better:
Pseudocode:
while (requested > 0)
{
    request = max(requested, ApiRequestMax)
    webService.Call(request)
    requested -= request
}
simply because it shows the intent of the code better.
 
Last edited:

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
5,251
Location
Chesapeake, VA
Programming Experience
10+
Of course, the above can be made into a for loop if you wish.
 

raysefo

Well-known member
Joined
Feb 22, 2019
Messages
237
Programming Experience
10+
@Skydiver How can I merge the responses? I mean if I request quantity = 200 game codes, there would be 20 separate responses. In my web API, I am inserting requests and responses into the database and sending JSON responses to the requester.
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
5,251
Location
Chesapeake, VA
Programming Experience
10+
If you are just passing through btht responses from the 3rd party, then the chances of merging together are pretty low if there is a requirement for repudiation. On the other hand, if it's your API that has to return a single response to the caller, the just return a single response after the loop. You can combine results from the 3rd Party any which you want since as far as your caller is concerned, they are talking to you, not the 3rd party -- you can make your own response format however you wish.
 

raysefo

Well-known member
Joined
Feb 22, 2019
Messages
237
Programming Experience
10+
In my opinion, a while loop would be better:
Pseudocode:
while (requested > 0)
{
    request = max(requested, ApiRequestMax)
    webService.Call(request)
    requested -= request
}
simply because it shows the intent of the code better.
If requested = 100 and ApiRequestMax = 10 and request will be 100. Web Service will give bad request because it can respond 10 max. Would it be min?
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
5,251
Location
Chesapeake, VA
Programming Experience
10+
Sorry my mistake. You want min(), not max().
 
Top Bottom