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 add_extern_service(self, name, portname, binding, location): """Add a service that was not defined in the wsdl. This is used after the Definitions object has been created. @param name: The name of the new service. @type url: str @param portname: The name of the port of the new service. @type portname: str @param binding: The name of the wsdl binding to use for the new service. The binding must be defined in the wsdl. @type binding: str @param location: The location of the new service. @type location: str """ if binding not in [bind[0] for bind in self.bindings.keys()]: log.debug('Binding "%s" not defined in %s' % (binding, self.url)) raise Exception('Binding "%s" not defined in %s' % (binding, self.url)) service = Element('service') service.set('name', name) port = Element('port', service) port.set('name', portname) port.set('binding', binding) address = Element('address', port) address.set('location', location) port.append(address) service.append(port) service = Factory.create(service, self) service.resolve(self) self.children.append(service) self.services.append(service) self.add_methods(service) log.debug('Created service: %s', service) return service