I am working on an application that needs to send/retrieve data from a SOAP API. The WSDL file is provided to me as a C# library and using the clr module I have built a class with all the functions I need from it.
class SoapAPI:
def __init__(self):
# Initialize Service
oBinding = BasicHttpBinding()
oBinding.Security.Mode = BasicHttpSecurityMode.Transport
oEndpointAddress = EndpointAddress(os.environ.get('API_URL'))
self.oService = ApiClient(oBinding, oEndpointAddress)
def function_a(self, foo):
# Do something
pass
def function_b(self, bar):
# Do something else
pass
def close(self):
# Close Service
self.oService.Close()
The issue I'm having is that connecting to the service takes about two seconds, making the application extremely slow for the user when viewing a page that requires access to the API.
I need an "always on" connection to the service.
I was thinking of creating a handler for these requests that would ensure the connection to the SOAP service is always active and would queue* the requests to be sent. However, I have no idea how to integrate this with Flask.
Should I create another app to which Flask will connect for these API calls instead?
*Requests need to be queued because as per the API docs I should not use more than 5 concurrent connections.