2

我们正在与 Vindicia 实施新的计费系统。Vindicia 有一个很棒的 wsdl 文件,可以很容易地创建一个模块。所以我们是 SUDS。但问题是 SUDS 在加载这些 wsdl 时真的很慢。(在我们的例子中,最多需要 2.4 秒)。

这是我使用 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

但这里的问题是cls.client = Client(url=wsdl, location=settings.VIN_SOAP_HOST) Takes 2 第一次看到。但是我们为新请求重用相同的对象,并且我们担心 SUDS 不是线程最安全的事实。

所以我们寻找另一个简单的解决方案。我们发现 pySimpleSoap 要快得多。

但是我们在加载 wsdl 期间遇到了递归错误。(哪个接缝是一个已知问题,代码中有一个 TODO 谈论递归)

...
    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>

因此,我们正在寻找一种可以降低 Wsdl 负载的解决方案。您会建议在创建客户端后对其进行缓存吗?那么重用呢?并且它需要易于实施。我们希望我们不必重新实现所有功能。

4

1 回答 1

2

请参阅Suds 没有重用缓存的 WSDL 和 XSD,尽管我希望它能够

这已经在我认为是维护最多的分支中进行了修补。

于 2014-03-24T16:12:33.073 回答