2014-01-23 85 views
2

我們正在使用Vindicia實施新的計費系統。 Vindicia有一個很棒的wsdl文件,可以很容易地創建一個模塊。所以我們是SUDS。但問題是,在加載這些wsdl時,SUDS真的很慢。 (在我們的情況下,它需要達到2.4秒)。WSDL緩慢加載SUDS

下面是我用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的負荷。你會建議在客戶端創建後緩存嗎?然後重用它? 它需要很容易實現。我們希望我們不必重新實現所有功能。

回答