我们正在与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)
第一次看到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负载的解决方案。你会建议在创建客户端之后缓存它吗?然后重复使用它? 它需要简单实现。我们希望我们不必重新实施所有职能。
答案 0 :(得分:2)