سؤال

We are implementing a new billing system with Vindicia. Vindicia has a great wsdl file that makes it easy to create a module with. So we are SUDS. But the problem is that SUDS is really slow at loading those wsdl. (In our case it takes up to 2.4 Sec).

Here is how I implemented it with SUDS.

class BaseWSDL(object):
    client = None
    group = ""
    instances = ""

    @classmethod
    def get_client(cls):
        if cls.client is None:
            wsdl = 'file://%s/%s.wsdl' % (wsdl_dir, cls.group)

            cls.client = Client(url=wsdl, location=host)
            setattr(cls, cls.instances.split(":")[1].lower(), cls.client.factory.create(cls.instances))
        return cls.client

class Authentication(object):
    def __init__(self, client, instances):
        self.authentication = client.factory.create(instances)
        self.authentication.login = login
        self.authentication.password = pw

class BillingPlan(BaseWSDL):
    group = "BillingPlan"
    instances = "ns2:BillingPlan"

    def __init__(self, **kwargs):
        super(BillingPlan, self).__init__()

    def fetch_all(self):
        client = self.get_client()
        auth = Authentication(client, "ns2:Authentication")
        response = client.service.fetchAll(auth.authentication)
        if response[0].returnCode == "200":
            plans_dict = {}
            for plan in response[1]:
                plans_dict[plan.merchantBillingPlanId] = plan
            return plans_dict

But the problem here is cls.client = Client(url=wsdl, location=settings.VIN_SOAP_HOST) Takes 2 sees the first time. But we reuse the same object for a new request and we are concerned by the fact that SUDS is not Thread safest.

So we looked for another simple solution. And we found that pySimpleSoap is much faster.

But we get a recursive error during the load of the wsdl. (which seam to be a known issue there is a TODO in the code talking about recursion)

...
    File "/usr/local/lib/python2.7/dist-packages/pysimplesoap/helpers.py", line 205, in postprocess_element
    postprocess_element(n)
  File "/usr/local/lib/python2.7/dist-packages/pysimplesoap/helpers.py", line 188, in postprocess_element
    postprocess_element(v)
  File "/usr/local/lib/python2.7/dist-packages/pysimplesoap/helpers.py", line 188, in postprocess_element
    postprocess_element(v)
  File "/usr/local/lib/python2.7/dist-packages/pysimplesoap/helpers.py", line 205, in postprocess_element
    postprocess_element(n)
  File "/usr/local/lib/python2.7/dist-packages/pysimplesoap/helpers.py", line 188, in postprocess_element
    postprocess_element(v)
  File "/usr/local/lib/python2.7/dist-packages/pysimplesoap/helpers.py", line 185, in postprocess_element
    for k, v in elements.items():
  File "/usr/local/lib/python2.7/dist-packages/pysimplesoap/simplexml.py", line 151, in items
    return [(key, self[key]) for key in self.__keys]
RuntimeError: maximum recursion depth exceeded while calling a Python object</code>

So we are looking at a solution that will lower the load on the Wsdl. Will you recommend to cache the client after it's created? then reuse it? And it need to be simple to implement. We wish we won't have to reimplement all the functions.

هل كانت مفيدة؟
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top