1. Phillip Alday
  2. suds

Commits

George Sakkis  committed bfb93b7

Auto service generation for Exchange ill-formed WSDL.
Ported from https://bitbucket.org/daevaorn/suds-ews/changeset/a96a57e1cb41

  • Participants
  • Parent commits 7510573
  • Branches default

Comments (0)

Files changed (1)

File suds/wsdl.py

View file
         self.resolve()
         self.build_schema()
         self.set_wrapped()
+        self._ensure_service()
         for s in self.services:
             self.add_methods(s)
         log.debug("WSDL at '%s' loaded:\n%s", url, self)
 
+    def _ensure_service(self):
+        """Trying to add service if no one definied explicitly. EWS workaround."""
+        if (self.services
+            or not self.bindings
+            or len(self.bindings) > 1
+            or not self.bindings.keys()[0][0].startswith('Exchange')):
+            return
+
+        service = Element('service')
+        service.set('name', 'ExchangeServices')
+
+        port = Element('port', service)
+        port.set('name', 'ExchangeServicePort')
+        port.set('binding', self.bindings.keys()[0][0])
+
+        address = Element('address', port)
+        address.set('location', urljoin(self.url, 'exchange.asmx'))
+
+        port.append(address)
+        service.append(port)
+
+        service = Factory.create(service, self)
+        service.resolve(self)
+
+        self.children.append(service)
+        self.services.append(service)
+
+        log.debug('Auto created service: %s', service)
+
     def mktns(self, root):
         """ Get/create the target namespace """
         tns = root.get('targetNamespace')