<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def invoke(self, method, _this, **kwargs):
 """Invoke a method on the server. :param method: The method to invoke, as found in the SDK. :type method: str :param _this: The managed object reference against which to invoke \ the method. :type _this: ManagedObject :param kwargs: The arguments to pass to the method, as \ found in the SDK. :type kwargs: TODO """

        if (self._logged_in is False and
            method not in ["Login", "RetrieveServiceContent"]):
            logger.critical("Cannot exec %s unless logged in", method)
            raise NotLoggedInError("Cannot exec %s unless logged in" % method)

        for kwarg in kwargs:
            kwargs[kwarg] = self._marshal(kwargs[kwarg])

        result = getattr(self.service, method)(_this=_this, **kwargs)
        if hasattr(result, '__iter__') is False:
            logger.debug("Returning non-iterable result")
            return result

        # We must traverse the result and convert any ManagedObjectReference
        # to a psphere class, this will then be lazy initialised on use
        logger.debug(result.__class__)
        logger.debug("Result: %s", result)
        logger.debug("Length: %s", len(result))
        if type(result) == list:
            new_result = []
            for item in result:
                new_result.append(self._unmarshal(item))
        else:
            new_result = self._unmarshal(result)
            
        logger.debug("Finished in invoke.")
        #property = self.find_and_destroy(property)
        #print result
        # Return the modified result to the caller
        return new_result