]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
ESX simplify SOAP request and response handling
authorMatthias Bolte <matthias.bolte@googlemail.com>
Fri, 4 Sep 2009 16:24:25 +0000 (18:24 +0200)
committerDaniel Veillard <veillard@redhat.com>
Fri, 4 Sep 2009 16:24:25 +0000 (18:24 +0200)
* src/esx/esx_vi.[ch]: convert esxVI_RemoteRequest_Execute() to a
  simpler esxVI_Context_Execute() version, remove esxVI_RemoteRequest
  and convert esxVI_RemoteResponse to esxVI_Response
* src/esx/esx_vi_methods.c: update and simplify callers to use
  esxVI_Context_Execute() instead of esxVI_RemoteRequest_Execute()

src/esx/esx_vi.c
src/esx/esx_vi.h
src/esx/esx_vi_methods.c

index 94195ee8e9833ea0cc5c6bca58ef9c7832e68e7a..a77cfda358386405c2431a9c14f578fdfa27f12d 100644 (file)
@@ -461,39 +461,21 @@ esxVI_Context_Download(virConnectPtr conn, esxVI_Context *ctx, const char *url,
     goto failure;
 }
 
-
-
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * RemoteRequest
- */
-
-/* esxVI_RemoteRequest_Alloc */
-ESX_VI__TEMPLATE__ALLOC(RemoteRequest);
-
-/* esxVI_RemoteRequest_Free */
-ESX_VI__TEMPLATE__FREE(RemoteRequest,
-{
-    VIR_FREE(item->request);
-    VIR_FREE(item->xpathExpression);
-});
-
 int
-esxVI_RemoteRequest_Execute(virConnectPtr conn, esxVI_Context *ctx,
-                            esxVI_RemoteRequest *remoteRequest,
-                            esxVI_RemoteResponse **remoteResponse,
-                            esxVI_Boolean expectList)
+esxVI_Context_Execute(virConnectPtr conn, esxVI_Context *ctx,
+                      const char *request, const char *xpathExpression,
+                      esxVI_Response **response, esxVI_Boolean expectList)
 {
     virBuffer buffer = VIR_BUFFER_INITIALIZER;
     esxVI_Fault *fault = NULL;
     CURLcode errorCode;
 
-    if (remoteRequest == NULL || remoteRequest->request == NULL ||
-        remoteResponse == NULL || *remoteResponse != NULL) {
+    if (request == NULL || response == NULL || *response != NULL) {
         ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid argument");
         goto failure;
     }
 
-    if (esxVI_RemoteResponse_Alloc(conn, remoteResponse) < 0) {
+    if (esxVI_Response_Alloc(conn, response) < 0) {
         goto failure;
     }
 
@@ -501,10 +483,8 @@ esxVI_RemoteRequest_Execute(virConnectPtr conn, esxVI_Context *ctx,
 
     curl_easy_setopt(ctx->curl_handle, CURLOPT_URL, ctx->url);
     curl_easy_setopt(ctx->curl_handle, CURLOPT_WRITEDATA, &buffer);
-    curl_easy_setopt(ctx->curl_handle, CURLOPT_POSTFIELDS,
-                     remoteRequest->request);
-    curl_easy_setopt(ctx->curl_handle, CURLOPT_POSTFIELDSIZE,
-                     strlen(remoteRequest->request));
+    curl_easy_setopt(ctx->curl_handle, CURLOPT_POSTFIELDS, request);
+    curl_easy_setopt(ctx->curl_handle, CURLOPT_POSTFIELDSIZE, strlen(request));
 
     errorCode = curl_easy_perform(ctx->curl_handle);
 
@@ -516,7 +496,7 @@ esxVI_RemoteRequest_Execute(virConnectPtr conn, esxVI_Context *ctx,
     }
 
     errorCode = curl_easy_getinfo(ctx->curl_handle, CURLINFO_RESPONSE_CODE,
-                                  &(*remoteResponse)->responseCode);
+                                  &(*response)->responseCode);
 
     if (errorCode != CURLE_OK) {
         ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
@@ -532,66 +512,62 @@ esxVI_RemoteRequest_Execute(virConnectPtr conn, esxVI_Context *ctx,
         goto failure;
     }
 
-    (*remoteResponse)->response = virBufferContentAndReset(&buffer);
+    (*response)->content = virBufferContentAndReset(&buffer);
 
-    if ((*remoteResponse)->responseCode == 500 ||
-        (remoteRequest->xpathExpression != NULL &&
-         (*remoteResponse)->responseCode == 200)) {
-        (*remoteResponse)->document =
-          xmlReadDoc(BAD_CAST(*remoteResponse)->response, "", NULL,
-                     XML_PARSE_NONET);
+    if ((*response)->responseCode == 500 ||
+        (xpathExpression != NULL && (*response)->responseCode == 200)) {
+        (*response)->document = xmlReadDoc(BAD_CAST (*response)->content, "",
+                                           NULL, XML_PARSE_NONET);
 
-        if ((*remoteResponse)->document == NULL) {
+        if ((*response)->document == NULL) {
             ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
                          "Could not parse XML response");
             goto failure;
         }
 
-        if (xmlDocGetRootElement((*remoteResponse)->document) == NULL) {
+        if (xmlDocGetRootElement((*response)->document) == NULL) {
             ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
                          "XML response is an empty document");
             goto failure;
         }
 
-        (*remoteResponse)->xpathContext =
-            xmlXPathNewContext((*remoteResponse)->document);
+        (*response)->xpathContext = xmlXPathNewContext((*response)->document);
 
-        if ((*remoteResponse)->xpathContext == NULL) {
+        if ((*response)->xpathContext == NULL) {
             ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
                          "Could not create XPath context");
             goto failure;
         }
 
-        xmlXPathRegisterNs((*remoteResponse)->xpathContext, BAD_CAST "soapenv",
+        xmlXPathRegisterNs((*response)->xpathContext, BAD_CAST "soapenv",
                            BAD_CAST "http://schemas.xmlsoap.org/soap/envelope/");
-        xmlXPathRegisterNs((*remoteResponse)->xpathContext, BAD_CAST "vim",
+        xmlXPathRegisterNs((*response)->xpathContext, BAD_CAST "vim",
                            BAD_CAST "urn:vim25");
 
-        if ((*remoteResponse)->responseCode == 500) {
-            (*remoteResponse)->node =
+        if ((*response)->responseCode == 500) {
+            (*response)->node =
               virXPathNode(conn, "/soapenv:Envelope/soapenv:Body/soapenv:Fault",
-                           (*remoteResponse)->xpathContext);
+                           (*response)->xpathContext);
 
-            if ((*remoteResponse)->node == NULL) {
+            if ((*response)->node == NULL) {
                 ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
                              "HTTP response code %d. VI Fault is unknown, "
                              "XPath evaluation failed",
-                             (int)(*remoteResponse)->responseCode);
+                             (int)(*response)->responseCode);
                 goto failure;
             }
 
-            if (esxVI_Fault_Deserialize(conn, (*remoteResponse)->node,
-                                        &fault) < 0) {
+            if (esxVI_Fault_Deserialize(conn, (*response)->node, &fault) < 0) {
                 ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
                              "HTTP response code %d. VI Fault is unknown, "
                              "deserialization failed",
-                             (int)(*remoteResponse)->responseCode);
+                             (int)(*response)->responseCode);
                 goto failure;
             }
 
             ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
                          "HTTP response code %d. VI Fault: %s - %s",
-                         (int)(*remoteResponse)->responseCode,
+                         (int)(*response)->responseCode,
                          fault->faultcode, fault->faultstring);
 
             goto failure;
@@ -599,38 +575,36 @@ esxVI_RemoteRequest_Execute(virConnectPtr conn, esxVI_Context *ctx,
             xmlNodePtr *nodeSet = NULL;
             int nodeSet_size;
 
-            nodeSet_size = virXPathNodeSet(conn, remoteRequest->xpathExpression,
-                                           (*remoteResponse)->xpathContext,
+            nodeSet_size = virXPathNodeSet(conn, xpathExpression,
+                                           (*response)->xpathContext,
                                            &nodeSet);
 
             if (nodeSet_size < 0) {
                 ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
                              "XPath evaluation of '%s' failed",
-                             remoteRequest->xpathExpression);
+                             xpathExpression);
                 goto failure;
             } else if (nodeSet_size == 0) {
-                (*remoteResponse)->node = NULL;
+                (*response)->node = NULL;
             } else {
-                (*remoteResponse)->node = nodeSet[0];
+                (*response)->node = nodeSet[0];
             }
 
             VIR_FREE(nodeSet);
         } else {
-            (*remoteResponse)->node =
-              virXPathNode(conn, remoteRequest->xpathExpression,
-                           (*remoteResponse)->xpathContext);
+            (*response)->node = virXPathNode(conn, xpathExpression,
+                                             (*response)->xpathContext);
 
-            if ((*remoteResponse)->node == NULL) {
+            if ((*response)->node == NULL) {
                 ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
                              "XPath evaluation of '%s' failed",
-                             remoteRequest->xpathExpression);
+                             xpathExpression);
                 goto failure;
             }
         }
-    } else if ((*remoteResponse)->responseCode != 200) {
+    } else if ((*response)->responseCode != 200) {
         ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
-                     "HTTP response code %d",
-                     (int)(*remoteResponse)->responseCode);
+                     "HTTP response code %d", (int)(*response)->responseCode);
 
         goto failure;
     }
@@ -639,7 +613,7 @@ esxVI_RemoteRequest_Execute(virConnectPtr conn, esxVI_Context *ctx,
 
   failure:
     free(virBufferContentAndReset(&buffer));
-    esxVI_RemoteResponse_Free(remoteResponse);
+    esxVI_Response_Free(response);
     esxVI_Fault_Free(&fault);
 
     return -1;
@@ -653,16 +627,16 @@ esxVI_RemoteRequest_Execute(virConnectPtr conn, esxVI_Context *ctx,
 
 
 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * RemoteResponse
+ * Response
  */
 
-/* esxVI_RemoteResponse_Alloc */
-ESX_VI__TEMPLATE__ALLOC(RemoteResponse);
+/* esxVI_Response_Alloc */
+ESX_VI__TEMPLATE__ALLOC(Response);
 
-/* esxVI_RemoteResponse_Free */
-ESX_VI__TEMPLATE__FREE(RemoteResponse,
+/* esxVI_Response_Free */
+ESX_VI__TEMPLATE__FREE(Response,
 {
-    VIR_FREE(item->response);
+    VIR_FREE(item->content);
 
     xmlXPathFreeContext(item->xpathContext);
 
@@ -1584,39 +1558,25 @@ esxVI_StartVirtualMachineTask(virConnectPtr conn, esxVI_Context *ctx,
                               esxVI_ManagedObjectReference **task)
 {
     int result = 0;
-    esxVI_RemoteRequest *remoteRequest = NULL;
-    esxVI_RemoteResponse *remoteResponse = NULL;
-
-    if (esxVI_RemoteRequest_Alloc(conn, &remoteRequest) < 0) {
-        goto failure;
-    }
+    char *xpathExpression = NULL;
+    esxVI_Response *response = NULL;
 
-    remoteRequest->request = (char *)request;
-
-    if (virAsprintf(&remoteRequest->xpathExpression,
+    if (virAsprintf(&xpathExpression,
                     ESX_VI__SOAP__RESPONSE_XPATH("%s_Task"), name) < 0) {
         virReportOOMError(conn);
         goto failure;
     }
 
-    if (esxVI_RemoteRequest_Execute(conn, ctx, remoteRequest, &remoteResponse,
-                                    esxVI_Boolean_False) < 0 ||
-        esxVI_ManagedObjectReference_Deserialize
-          (conn, remoteResponse->node, task, "Task") < 0) {
+    if (esxVI_Context_Execute(conn, ctx, request, xpathExpression, &response,
+                              esxVI_Boolean_False) < 0 ||
+        esxVI_ManagedObjectReference_Deserialize(conn, response->node, task,
+                                                 "Task") < 0) {
         goto failure;
     }
 
   cleanup:
-    /*
-     * Remove values given by the caller from the data structures to prevent
-     * them from being freed by the call to esxVI_RemoteRequest_Free().
-     */
-    if (remoteRequest != NULL) {
-        remoteRequest->request = NULL;
-    }
-
-    esxVI_RemoteRequest_Free(&remoteRequest);
-    esxVI_RemoteResponse_Free(&remoteResponse);
+    VIR_FREE(xpathExpression);
+    esxVI_Response_Free(&response);
 
     return result;
 
@@ -1682,13 +1642,13 @@ esxVI_StartSimpleVirtualMachineTask
 
 int
 esxVI_SimpleVirtualMachineMethod(virConnectPtr conn, esxVI_Context *ctx,
-                                const char *name,
-                                esxVI_ManagedObjectReference *virtualMachine)
+                                 const char *name,
+                                 esxVI_ManagedObjectReference *virtualMachine)
 {
     int result = 0;
-    esxVI_RemoteRequest *remoteRequest = NULL;
-    esxVI_RemoteResponse *remoteResponse = NULL;
     virBuffer buffer = VIR_BUFFER_INITIALIZER;
+    char *request = NULL;
+    esxVI_Response *response = NULL;
 
     if (ctx->service == NULL) {
         ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid argument");
@@ -1700,8 +1660,7 @@ esxVI_SimpleVirtualMachineMethod(virConnectPtr conn, esxVI_Context *ctx,
     virBufferAdd(&buffer, name, -1);
     virBufferAddLit(&buffer, " xmlns=\"urn:vim25\">");
 
-    if (esxVI_RemoteRequest_Alloc(conn, &remoteRequest) < 0 ||
-        esxVI_ManagedObjectReference_Serialize(conn, virtualMachine, "_this",
+    if (esxVI_ManagedObjectReference_Serialize(conn, virtualMachine, "_this",
                                                &buffer,
                                                esxVI_Boolean_True) < 0) {
         goto failure;
@@ -1717,21 +1676,23 @@ esxVI_SimpleVirtualMachineMethod(virConnectPtr conn, esxVI_Context *ctx,
         goto failure;
     }
 
-    remoteRequest->request = virBufferContentAndReset(&buffer);
+    request = virBufferContentAndReset(&buffer);
 
-    if (esxVI_RemoteRequest_Execute(conn, ctx, remoteRequest, &remoteResponse,
-                                    esxVI_Boolean_False) < 0) {
+    if (esxVI_Context_Execute(conn, ctx, request, NULL, &response,
+                              esxVI_Boolean_False) < 0) {
         goto failure;
     }
 
   cleanup:
-    esxVI_RemoteRequest_Free(&remoteRequest);
-    esxVI_RemoteResponse_Free(&remoteResponse);
+    VIR_FREE(request);
+    esxVI_Response_Free(&response);
 
     return result;
 
   failure:
-    free(virBufferContentAndReset(&buffer));
+    if (request == NULL) {
+        request = virBufferContentAndReset(&buffer);
+    }
 
     result = -1;
 
index bed4a901dc105025b686056a600be102f2a7b10c..e60ac7f1c148922236684577a69f19e6718da798 100644 (file)
@@ -34,8 +34,7 @@
 typedef enum _esxVI_APIVersion esxVI_APIVersion;
 typedef enum _esxVI_ProductVersion esxVI_ProductVersion;
 typedef struct _esxVI_Context esxVI_Context;
-typedef struct _esxVI_RemoteResponse esxVI_RemoteResponse;
-typedef struct _esxVI_RemoteRequest esxVI_RemoteRequest;
+typedef struct _esxVI_Response esxVI_Response;
 typedef struct _esxVI_Enumeration esxVI_Enumeration;
 typedef struct _esxVI_EnumerationValue esxVI_EnumerationValue;
 typedef struct _esxVI_List esxVI_List;
@@ -88,43 +87,26 @@ int esxVI_Context_Connect(virConnectPtr conn, esxVI_Context *ctx,
                           const char *password, int noVerify);
 int esxVI_Context_Download(virConnectPtr conn, esxVI_Context *ctx,
                            const char *url, char **content);
+int esxVI_Context_Execute(virConnectPtr conn, esxVI_Context *ctx,
+                          const char *request, const char *xpathExpression,
+                          esxVI_Response **response, esxVI_Boolean expectList);
 
 
 
 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * RemoteRequest
+ * Response
  */
 
-struct _esxVI_RemoteRequest {
-    char *request;                                    /* required */
-    char *xpathExpression;                            /* optional */
-};
-
-int esxVI_RemoteRequest_Alloc(virConnectPtr conn,
-                              esxVI_RemoteRequest **remoteRequest);
-void esxVI_RemoteRequest_Free(esxVI_RemoteRequest **remoteRequest);
-int esxVI_RemoteRequest_Execute(virConnectPtr conn, esxVI_Context *ctx,
-                                esxVI_RemoteRequest *remoteRequest,
-                                esxVI_RemoteResponse **remoteResponse,
-                                esxVI_Boolean expectList);
-
-
-
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * RemoteResponse
- */
-
-struct _esxVI_RemoteResponse {
+struct _esxVI_Response {
     long responseCode;                                /* required */
-    char *response;                                   /* required */
+    char *content;                                    /* required */
     xmlDocPtr document;                               /* optional */
     xmlXPathContextPtr xpathContext;                  /* optional */
     xmlNodePtr node;                                  /* optional, list */
 };
 
-int esxVI_RemoteResponse_Alloc(virConnectPtr conn,
-                               esxVI_RemoteResponse **remoteResponse);
-void esxVI_RemoteResponse_Free(esxVI_RemoteResponse **remoteResponse);
+int esxVI_Response_Alloc(virConnectPtr conn, esxVI_Response **response);
+void esxVI_Response_Free(esxVI_Response **response);
 
 
 
index 4462063601f7e0634ec94677ce7ef235bdf7e7b6..3bc5e43320d140d6378177bd70f7e2bfee1b8b38 100644 (file)
@@ -50,8 +50,7 @@
     "</soapenv:Envelope>"
 
 #define ESX_VI__SOAP__RESPONSE_XPATH(_type)                                   \
-    ((char *)"/soapenv:Envelope/soapenv:Body/"                                \
-             "vim:"_type"Response/vim:returnval")
+    "/soapenv:Envelope/soapenv:Body/vim:"_type"Response/vim:returnval"
 
 
 
  * VI Methods
  */
 
-static const char *_esxVI_RetrieveServiceContentRequest =
-ESX_VI__SOAP__REQUEST_HEADER
-  "<RetrieveServiceContent xmlns=\"urn:vim25\">"
-    "<_this xmlns=\"urn:vim25\" "
-           "xsi:type=\"ManagedObjectReference\" "
-           "type=\"ServiceInstance\">"
-      "ServiceInstance"
-    "</_this>"
-  "</RetrieveServiceContent>"
-ESX_VI__SOAP__REQUEST_FOOTER;
-
 int
 esxVI_RetrieveServiceContent(virConnectPtr conn, esxVI_Context *ctx,
                              esxVI_ServiceContent **serviceContent)
 {
     int result = 0;
-    esxVI_RemoteRequest *remoteRequest = NULL;
-    esxVI_RemoteResponse *remoteResponse = NULL;
+    const char *request = ESX_VI__SOAP__REQUEST_HEADER
+                            "<RetrieveServiceContent xmlns=\"urn:vim25\">"
+                              "<_this xmlns=\"urn:vim25\" "
+                                     "xsi:type=\"ManagedObjectReference\" "
+                                     "type=\"ServiceInstance\">"
+                                "ServiceInstance"
+                              "</_this>"
+                            "</RetrieveServiceContent>"
+                          ESX_VI__SOAP__REQUEST_FOOTER;
+    esxVI_Response *response = NULL;
 
     if (serviceContent == NULL || *serviceContent != NULL) {
         ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid argument");
         return -1;
     }
 
-    if (esxVI_RemoteRequest_Alloc(conn, &remoteRequest) < 0) {
-        goto failure;
-    }
-
-    remoteRequest->request = (char *)_esxVI_RetrieveServiceContentRequest;
-    remoteRequest->xpathExpression =
-      ESX_VI__SOAP__RESPONSE_XPATH("RetrieveServiceContent");
-
-    if (esxVI_RemoteRequest_Execute(conn, ctx, remoteRequest, &remoteResponse,
-                                    esxVI_Boolean_False) < 0 ||
-        esxVI_ServiceContent_Deserialize(conn, remoteResponse->node,
+    if (esxVI_Context_Execute(conn, ctx, request,
+                              ESX_VI__SOAP__RESPONSE_XPATH("RetrieveServiceContent"),
+                              &response, esxVI_Boolean_False) < 0 ||
+        esxVI_ServiceContent_Deserialize(conn, response->node,
                                          serviceContent) < 0) {
         goto failure;
     }
 
   cleanup:
-    /*
-     * Remove static values from the data structures to prevent them from
-     * being freed by the call to esxVI_RemoteRequest_Free().
-     */
-    if (remoteRequest != NULL) {
-        remoteRequest->request = NULL;
-        remoteRequest->xpathExpression = NULL;
-    }
-
-    esxVI_RemoteRequest_Free(&remoteRequest);
-    esxVI_RemoteResponse_Free(&remoteResponse);
+    esxVI_Response_Free(&response);
 
     return result;
 
@@ -127,9 +106,9 @@ esxVI_Login(virConnectPtr conn, esxVI_Context *ctx,
             esxVI_UserSession **userSession)
 {
     int result = 0;
-    esxVI_RemoteRequest *remoteRequest = NULL;
-    esxVI_RemoteResponse *remoteResponse = NULL;
     virBuffer buffer = VIR_BUFFER_INITIALIZER;
+    char *request = NULL;
+    esxVI_Response *response = NULL;
 
     if (ctx->service == NULL) {
         ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid call");
@@ -144,8 +123,7 @@ esxVI_Login(virConnectPtr conn, esxVI_Context *ctx,
     virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
     virBufferAddLit(&buffer, "<Login xmlns=\"urn:vim25\">");
 
-    if (esxVI_RemoteRequest_Alloc(conn, &remoteRequest) < 0 ||
-        esxVI_ManagedObjectReference_Serialize(conn,
+    if (esxVI_ManagedObjectReference_Serialize(conn,
                                                ctx->service->sessionManager,
                                                "_this", &buffer,
                                                esxVI_Boolean_True) < 0 ||
@@ -164,32 +142,25 @@ esxVI_Login(virConnectPtr conn, esxVI_Context *ctx,
         goto failure;
     }
 
-    remoteRequest->request = virBufferContentAndReset(&buffer);
-    remoteRequest->xpathExpression = ESX_VI__SOAP__RESPONSE_XPATH("Login");
+    request = virBufferContentAndReset(&buffer);
 
-    if (esxVI_RemoteRequest_Execute(conn, ctx, remoteRequest, &remoteResponse,
-                                    esxVI_Boolean_False) < 0 ||
-        esxVI_UserSession_Deserialize(conn, remoteResponse->node,
-                                      userSession) < 0) {
+    if (esxVI_Context_Execute(conn, ctx, request,
+                              ESX_VI__SOAP__RESPONSE_XPATH("Login"),
+                              &response, esxVI_Boolean_False) < 0 ||
+        esxVI_UserSession_Deserialize(conn, response->node, userSession) < 0) {
         goto failure;
     }
 
   cleanup:
-    /*
-     * Remove static values from the data structures to prevent them from
-     * being freed by the call to esxVI_RemoteRequest_Free().
-     */
-    if (remoteRequest != NULL) {
-        remoteRequest->xpathExpression = NULL;
-    }
-
-    esxVI_RemoteRequest_Free(&remoteRequest);
-    esxVI_RemoteResponse_Free(&remoteResponse);
+    VIR_FREE(request);
+    esxVI_Response_Free(&response);
 
     return result;
 
   failure:
-    free(virBufferContentAndReset(&buffer));
+    if (request == NULL) {
+        request = virBufferContentAndReset(&buffer);
+    }
 
     result = -1;
 
@@ -202,9 +173,9 @@ int
 esxVI_Logout(virConnectPtr conn, esxVI_Context *ctx)
 {
     int result = 0;
-    esxVI_RemoteRequest *remoteRequest = NULL;
-    esxVI_RemoteResponse *remoteResponse = NULL;
     virBuffer buffer = VIR_BUFFER_INITIALIZER;
+    char *request = NULL;
+    esxVI_Response *response = NULL;
 
     if (ctx->service == NULL) {
         ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid call");
@@ -214,8 +185,7 @@ esxVI_Logout(virConnectPtr conn, esxVI_Context *ctx)
     virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
     virBufferAddLit(&buffer, "<Logout xmlns=\"urn:vim25\">");
 
-    if (esxVI_RemoteRequest_Alloc(conn, &remoteRequest) < 0 ||
-        esxVI_ManagedObjectReference_Serialize(conn,
+    if (esxVI_ManagedObjectReference_Serialize(conn,
                                                ctx->service->sessionManager,
                                                "_this", &buffer,
                                                esxVI_Boolean_True) < 0) {
@@ -230,21 +200,23 @@ esxVI_Logout(virConnectPtr conn, esxVI_Context *ctx)
         goto failure;
     }
 
-    remoteRequest->request = virBufferContentAndReset(&buffer);
+    request = virBufferContentAndReset(&buffer);
 
-    if (esxVI_RemoteRequest_Execute(conn, ctx, remoteRequest, &remoteResponse,
-                                    esxVI_Boolean_False) < 0) {
+    if (esxVI_Context_Execute(conn, ctx, request, NULL, &response,
+                              esxVI_Boolean_False) < 0) {
         goto failure;
     }
 
   cleanup:
-    esxVI_RemoteRequest_Free(&remoteRequest);
-    esxVI_RemoteResponse_Free(&remoteResponse);
+    VIR_FREE(request);
+    esxVI_Response_Free(&response);
 
     return result;
 
   failure:
-    free(virBufferContentAndReset(&buffer));
+    if (request == NULL) {
+        request = virBufferContentAndReset(&buffer);
+    }
 
     result = -1;
 
@@ -259,9 +231,9 @@ esxVI_SessionIsActive(virConnectPtr conn, esxVI_Context *ctx,
                       esxVI_Boolean *active)
 {
     int result = 0;
-    esxVI_RemoteRequest *remoteRequest = NULL;
-    esxVI_RemoteResponse *remoteResponse = NULL;
     virBuffer buffer = VIR_BUFFER_INITIALIZER;
+    char *request = NULL;
+    esxVI_Response *response = NULL;
 
     if (ctx->service == NULL) {
         ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid call");
@@ -276,8 +248,7 @@ esxVI_SessionIsActive(virConnectPtr conn, esxVI_Context *ctx,
     virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
     virBufferAddLit(&buffer, "<SessionIsActive xmlns=\"urn:vim25\">");
 
-    if (esxVI_RemoteRequest_Alloc(conn, &remoteRequest) < 0 ||
-        esxVI_ManagedObjectReference_Serialize(conn,
+    if (esxVI_ManagedObjectReference_Serialize(conn,
                                                ctx->service->sessionManager,
                                                "_this", &buffer,
                                                esxVI_Boolean_True) < 0 ||
@@ -296,32 +267,25 @@ esxVI_SessionIsActive(virConnectPtr conn, esxVI_Context *ctx,
         goto failure;
     }
 
-    remoteRequest->request = virBufferContentAndReset(&buffer);
-    remoteRequest->xpathExpression =
-      ESX_VI__SOAP__RESPONSE_XPATH("SessionIsActive");
+    request = virBufferContentAndReset(&buffer);
 
-    if (esxVI_RemoteRequest_Execute(conn, ctx, remoteRequest, &remoteResponse,
-                                    esxVI_Boolean_False) < 0 ||
-        esxVI_Boolean_Deserialize(conn, remoteResponse->node, active) < 0) {
+    if (esxVI_Context_Execute(conn, ctx, request,
+                              ESX_VI__SOAP__RESPONSE_XPATH("SessionIsActive"),
+                              &response, esxVI_Boolean_False) < 0 ||
+        esxVI_Boolean_Deserialize(conn, response->node, active) < 0) {
         goto failure;
     }
 
   cleanup:
-    /*
-     * Remove static values from the data structures to prevent them from
-     * being freed by the call to esxVI_RemoteRequest_Free().
-     */
-    if (remoteRequest != NULL) {
-        remoteRequest->xpathExpression = NULL;
-    }
-
-    esxVI_RemoteRequest_Free(&remoteRequest);
-    esxVI_RemoteResponse_Free(&remoteResponse);
+    VIR_FREE(request);
+    esxVI_Response_Free(&response);
 
     return result;
 
   failure:
-    free(virBufferContentAndReset(&buffer));
+    if (request == NULL) {
+        request = virBufferContentAndReset(&buffer);
+    }
 
     result = -1;
 
@@ -336,9 +300,9 @@ esxVI_RetrieveProperties(virConnectPtr conn, esxVI_Context *ctx,
                          esxVI_ObjectContent **objectContentList)
 {
     int result = 0;
-    esxVI_RemoteRequest *remoteRequest = NULL;
-    esxVI_RemoteResponse *remoteResponse = NULL;
     virBuffer buffer = VIR_BUFFER_INITIALIZER;
+    char *request = NULL;
+    esxVI_Response *response = NULL;
 
     if (ctx->service == NULL) {
         ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid call");
@@ -353,8 +317,7 @@ esxVI_RetrieveProperties(virConnectPtr conn, esxVI_Context *ctx,
     virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
     virBufferAddLit(&buffer, "<RetrieveProperties xmlns=\"urn:vim25\">");
 
-    if (esxVI_RemoteRequest_Alloc(conn, &remoteRequest) < 0 ||
-        esxVI_ManagedObjectReference_Serialize(conn,
+    if (esxVI_ManagedObjectReference_Serialize(conn,
                                                ctx->service->propertyCollector,
                                                "_this", &buffer,
                                                esxVI_Boolean_True) < 0 ||
@@ -372,33 +335,26 @@ esxVI_RetrieveProperties(virConnectPtr conn, esxVI_Context *ctx,
         goto failure;
     }
 
-    remoteRequest->request = virBufferContentAndReset(&buffer);
-    remoteRequest->xpathExpression =
-      ESX_VI__SOAP__RESPONSE_XPATH("RetrieveProperties");
+    request = virBufferContentAndReset(&buffer);
 
-    if (esxVI_RemoteRequest_Execute(conn, ctx, remoteRequest, &remoteResponse,
-                                    esxVI_Boolean_True) < 0 ||
-        esxVI_ObjectContent_DeserializeList(conn, remoteResponse->node,
+    if (esxVI_Context_Execute(conn, ctx, request,
+                              ESX_VI__SOAP__RESPONSE_XPATH("RetrieveProperties"),
+                              &response, esxVI_Boolean_True) < 0 ||
+        esxVI_ObjectContent_DeserializeList(conn, response->node,
                                             objectContentList) < 0) {
         goto failure;
     }
 
   cleanup:
-    /*
-     * Remove static values from the data structures to prevent them from
-     * being freed by the call to esxVI_RemoteRequest_Free().
-     */
-    if (remoteRequest != NULL) {
-        remoteRequest->xpathExpression = NULL;
-    }
-
-    esxVI_RemoteRequest_Free(&remoteRequest);
-    esxVI_RemoteResponse_Free(&remoteResponse);
+    VIR_FREE(request);
+    esxVI_Response_Free(&response);
 
     return result;
 
   failure:
-    free(virBufferContentAndReset(&buffer));
+    if (request == NULL) {
+        request = virBufferContentAndReset(&buffer);
+    }
 
     result = -1;
 
@@ -495,7 +451,9 @@ esxVI_MigrateVM_Task(virConnectPtr conn, esxVI_Context *ctx,
     return result;
 
   failure:
-    free(virBufferContentAndReset(&buffer));
+    if (request == NULL) {
+        request = virBufferContentAndReset(&buffer);
+    }
 
     result = -1;
 
@@ -551,7 +509,9 @@ esxVI_ReconfigVM_Task(virConnectPtr conn, esxVI_Context *ctx,
     return result;
 
   failure:
-    free(virBufferContentAndReset(&buffer));
+    if (request == NULL) {
+        request = virBufferContentAndReset(&buffer);
+    }
 
     result = -1;
 
@@ -567,9 +527,9 @@ esxVI_CreateFilter(virConnectPtr conn, esxVI_Context *ctx,
                    esxVI_ManagedObjectReference **propertyFilter)
 {
     int result = 0;
-    esxVI_RemoteRequest *remoteRequest = NULL;
-    esxVI_RemoteResponse *remoteResponse = NULL;
     virBuffer buffer = VIR_BUFFER_INITIALIZER;
+    char *request = NULL;
+    esxVI_Response *response = NULL;
 
     if (ctx->service == NULL) {
         ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid call");
@@ -584,8 +544,7 @@ esxVI_CreateFilter(virConnectPtr conn, esxVI_Context *ctx,
     virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
     virBufferAddLit(&buffer, "<CreateFilter xmlns=\"urn:vim25\">");
 
-    if (esxVI_RemoteRequest_Alloc(conn, &remoteRequest) < 0 ||
-        esxVI_ManagedObjectReference_Serialize(conn,
+    if (esxVI_ManagedObjectReference_Serialize(conn,
                                                ctx->service->propertyCollector,
                                                "_this", &buffer,
                                                esxVI_Boolean_True) < 0 ||
@@ -604,33 +563,27 @@ esxVI_CreateFilter(virConnectPtr conn, esxVI_Context *ctx,
         goto failure;
     }
 
-    remoteRequest->request = virBufferContentAndReset(&buffer);
-    remoteRequest->xpathExpression =
-      ESX_VI__SOAP__RESPONSE_XPATH("CreateFilter");
+    request = virBufferContentAndReset(&buffer);
 
-    if (esxVI_RemoteRequest_Execute(conn, ctx, remoteRequest, &remoteResponse,
-                                    esxVI_Boolean_False) < 0 ||
-        esxVI_ManagedObjectReference_Deserialize
-          (conn, remoteResponse->node, propertyFilter, "PropertyFilter") < 0) {
+    if (esxVI_Context_Execute(conn, ctx, request,
+                              ESX_VI__SOAP__RESPONSE_XPATH("CreateFilter"),
+                              &response, esxVI_Boolean_False) < 0 ||
+        esxVI_ManagedObjectReference_Deserialize(conn, response->node,
+                                                 propertyFilter,
+                                                 "PropertyFilter") < 0) {
         goto failure;
     }
 
   cleanup:
-    /*
-     * Remove static values from the data structures to prevent them from
-     * being freed by the call to esxVI_RemoteRequest_Free().
-     */
-    if (remoteRequest != NULL) {
-        remoteRequest->xpathExpression = NULL;
-    }
-
-    esxVI_RemoteRequest_Free(&remoteRequest);
-    esxVI_RemoteResponse_Free(&remoteResponse);
+    VIR_FREE(request);
+    esxVI_Response_Free(&response);
 
     return result;
 
   failure:
-    free(virBufferContentAndReset(&buffer));
+    if (request == NULL) {
+        request = virBufferContentAndReset(&buffer);
+    }
 
     result = -1;
 
@@ -644,9 +597,9 @@ esxVI_DestroyPropertyFilter(virConnectPtr conn, esxVI_Context *ctx,
                             esxVI_ManagedObjectReference *propertyFilter)
 {
     int result = 0;
-    esxVI_RemoteRequest *remoteRequest = NULL;
-    esxVI_RemoteResponse *remoteResponse = NULL;
     virBuffer buffer = VIR_BUFFER_INITIALIZER;
+    char *request = NULL;
+    esxVI_Response *response = NULL;
 
     if (ctx->service == NULL) {
         ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid call");
@@ -656,8 +609,7 @@ esxVI_DestroyPropertyFilter(virConnectPtr conn, esxVI_Context *ctx,
     virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
     virBufferAddLit(&buffer, "<DestroyPropertyFilter xmlns=\"urn:vim25\">");
 
-    if (esxVI_RemoteRequest_Alloc(conn, &remoteRequest) < 0 ||
-        esxVI_ManagedObjectReference_Serialize(conn, propertyFilter, "_this",
+    if (esxVI_ManagedObjectReference_Serialize(conn, propertyFilter, "_this",
                                                &buffer,
                                                esxVI_Boolean_True) < 0) {
         goto failure;
@@ -671,21 +623,23 @@ esxVI_DestroyPropertyFilter(virConnectPtr conn, esxVI_Context *ctx,
         goto failure;
     }
 
-    remoteRequest->request = virBufferContentAndReset(&buffer);
+    request = virBufferContentAndReset(&buffer);
 
-    if (esxVI_RemoteRequest_Execute(conn, ctx, remoteRequest, &remoteResponse,
-                                    esxVI_Boolean_False) < 0) {
+    if (esxVI_Context_Execute(conn, ctx, request, NULL, &response,
+                              esxVI_Boolean_False) < 0) {
         goto failure;
     }
 
   cleanup:
-    esxVI_RemoteRequest_Free(&remoteRequest);
-    esxVI_RemoteResponse_Free(&remoteResponse);
+    VIR_FREE(request);
+    esxVI_Response_Free(&response);
 
     return result;
 
   failure:
-    free(virBufferContentAndReset(&buffer));
+    if (request == NULL) {
+        request = virBufferContentAndReset(&buffer);
+    }
 
     result = -1;
 
@@ -699,9 +653,9 @@ esxVI_WaitForUpdates(virConnectPtr conn, esxVI_Context *ctx,
                      const char *version, esxVI_UpdateSet **updateSet)
 {
     int result = 0;
-    esxVI_RemoteRequest *remoteRequest = NULL;
-    esxVI_RemoteResponse *remoteResponse = NULL;
     virBuffer buffer = VIR_BUFFER_INITIALIZER;
+    char *request = NULL;
+    esxVI_Response *response = NULL;
 
     if (ctx->service == NULL) {
         ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid call");
@@ -716,8 +670,7 @@ esxVI_WaitForUpdates(virConnectPtr conn, esxVI_Context *ctx,
     virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
     virBufferAddLit(&buffer, "<WaitForUpdates xmlns=\"urn:vim25\">");
 
-    if (esxVI_RemoteRequest_Alloc(conn, &remoteRequest) < 0 ||
-        esxVI_ManagedObjectReference_Serialize(conn,
+    if (esxVI_ManagedObjectReference_Serialize(conn,
                                                ctx->service->propertyCollector,
                                                "_this", &buffer,
                                                esxVI_Boolean_True) < 0 ||
@@ -734,33 +687,25 @@ esxVI_WaitForUpdates(virConnectPtr conn, esxVI_Context *ctx,
         goto failure;
     }
 
-    remoteRequest->request = virBufferContentAndReset(&buffer);
-    remoteRequest->xpathExpression =
-      ESX_VI__SOAP__RESPONSE_XPATH("WaitForUpdates");
+    request = virBufferContentAndReset(&buffer);
 
-    if (esxVI_RemoteRequest_Execute(conn, ctx, remoteRequest, &remoteResponse,
-                                    esxVI_Boolean_False) < 0 ||
-        esxVI_UpdateSet_Deserialize(conn, remoteResponse->node,
-                                    updateSet) < 0) {
+    if (esxVI_Context_Execute(conn, ctx, request,
+                              ESX_VI__SOAP__RESPONSE_XPATH("WaitForUpdates"),
+                              &response, esxVI_Boolean_False) < 0 ||
+        esxVI_UpdateSet_Deserialize(conn, response->node, updateSet) < 0) {
         goto failure;
     }
 
   cleanup:
-    /*
-     * Remove static values from the data structures to prevent them from
-     * being freed by the call to esxVI_RemoteRequest_Free().
-     */
-    if (remoteRequest != NULL) {
-        remoteRequest->xpathExpression = NULL;
-    }
-
-    esxVI_RemoteRequest_Free(&remoteRequest);
-    esxVI_RemoteResponse_Free(&remoteResponse);
+    VIR_FREE(request);
+    esxVI_Response_Free(&response);
 
     return result;
 
   failure:
-    free(virBufferContentAndReset(&buffer));
+    if (request == NULL) {
+        request = virBufferContentAndReset(&buffer);
+    }
 
     result = -1;
 
@@ -799,9 +744,9 @@ esxVI_ValidateMigration(virConnectPtr conn, esxVI_Context *ctx,
                         esxVI_Event **eventList)
 {
     int result = 0;
-    esxVI_RemoteRequest *remoteRequest = NULL;
-    esxVI_RemoteResponse *remoteResponse = NULL;
     virBuffer buffer = VIR_BUFFER_INITIALIZER;
+    char *request = NULL;
+    esxVI_Response *response = NULL;
 
     if (ctx->service == NULL) {
         ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid call");
@@ -821,8 +766,7 @@ esxVI_ValidateMigration(virConnectPtr conn, esxVI_Context *ctx,
                                "ServiceInstance"
                              "</_this>");
 
-    if (esxVI_RemoteRequest_Alloc(conn, &remoteRequest) < 0 ||
-        esxVI_ManagedObjectReference_SerializeList(conn, virtualMachineList,
+    if (esxVI_ManagedObjectReference_SerializeList(conn, virtualMachineList,
                                                    "vm", &buffer,
                                                    esxVI_Boolean_True) < 0 ||
         esxVI_VirtualMachinePowerState_Serialize(conn, powerState, "state",
@@ -847,33 +791,25 @@ esxVI_ValidateMigration(virConnectPtr conn, esxVI_Context *ctx,
         goto failure;
     }
 
-    remoteRequest->request = virBufferContentAndReset(&buffer);
-    remoteRequest->xpathExpression =
-      ESX_VI__SOAP__RESPONSE_XPATH("ValidateMigration");
+    request = virBufferContentAndReset(&buffer);
 
-    if (esxVI_RemoteRequest_Execute(conn, ctx, remoteRequest, &remoteResponse,
-                                    esxVI_Boolean_True) < 0 ||
-        esxVI_Event_DeserializeList(conn, remoteResponse->node,
-                                    eventList) < 0) {
+    if (esxVI_Context_Execute(conn, ctx, request,
+                              ESX_VI__SOAP__RESPONSE_XPATH("ValidateMigration"),
+                              &response, esxVI_Boolean_True) < 0 ||
+        esxVI_Event_DeserializeList(conn, response->node, eventList) < 0) {
         goto failure;
     }
 
   cleanup:
-    /*
-     * Remove static values from the data structures to prevent them from
-     * being freed by the call to esxVI_RemoteRequest_Free().
-     */
-    if (remoteRequest != NULL) {
-        remoteRequest->xpathExpression = NULL;
-    }
-
-    esxVI_RemoteRequest_Free(&remoteRequest);
-    esxVI_RemoteResponse_Free(&remoteResponse);
+    VIR_FREE(request);
+    esxVI_Response_Free(&response);
 
     return result;
 
   failure:
-    free(virBufferContentAndReset(&buffer));
+    if (request == NULL) {
+        request = virBufferContentAndReset(&buffer);
+    }
 
     result = -1;
 
@@ -889,9 +825,9 @@ esxVI_FindByIp(virConnectPtr conn, esxVI_Context *ctx,
                  esxVI_ManagedObjectReference **managedObjectReference)
 {
     int result = 0;
-    esxVI_RemoteRequest *remoteRequest = NULL;
-    esxVI_RemoteResponse *remoteResponse = NULL;
     virBuffer buffer = VIR_BUFFER_INITIALIZER;
+    char *request = NULL;
+    esxVI_Response *response = NULL;
 
     if (ctx->service == NULL) {
         ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid call");
@@ -906,8 +842,7 @@ esxVI_FindByIp(virConnectPtr conn, esxVI_Context *ctx,
     virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
     virBufferAddLit(&buffer, "<FindByIp xmlns=\"urn:vim25\">");
 
-    if (esxVI_RemoteRequest_Alloc(conn, &remoteRequest) < 0 ||
-        esxVI_ManagedObjectReference_Serialize(conn, ctx->service->searchIndex,
+    if (esxVI_ManagedObjectReference_Serialize(conn, ctx->service->searchIndex,
                                                "_this", &buffer,
                                                esxVI_Boolean_True) < 0 ||
         esxVI_ManagedObjectReference_Serialize(conn, datacenter,
@@ -928,35 +863,28 @@ esxVI_FindByIp(virConnectPtr conn, esxVI_Context *ctx,
         goto failure;
     }
 
-    remoteRequest->request = virBufferContentAndReset(&buffer);
-    remoteRequest->xpathExpression =
-      ESX_VI__SOAP__RESPONSE_XPATH("FindByIp");
+    request = virBufferContentAndReset(&buffer);
 
-    if (esxVI_RemoteRequest_Execute(conn, ctx, remoteRequest, &remoteResponse,
-                                    esxVI_Boolean_False) < 0 ||
+    if (esxVI_Context_Execute(conn, ctx, request,
+                              ESX_VI__SOAP__RESPONSE_XPATH("FindByIp"),
+                              &response, esxVI_Boolean_False) < 0 ||
         esxVI_ManagedObjectReference_Deserialize
-          (conn, remoteResponse->node, managedObjectReference,
+          (conn, response->node, managedObjectReference,
            vmSearch == esxVI_Boolean_True ? "VirtualMachine"
                                           : "HostSystem") < 0) {
         goto failure;
     }
 
   cleanup:
-    /*
-     * Remove static values from the data structures to prevent them from
-     * being freed by the call to esxVI_RemoteRequest_Free().
-     */
-    if (remoteRequest != NULL) {
-        remoteRequest->xpathExpression = NULL;
-    }
-
-    esxVI_RemoteRequest_Free(&remoteRequest);
-    esxVI_RemoteResponse_Free(&remoteResponse);
+    VIR_FREE(request);
+    esxVI_Response_Free(&response);
 
     return result;
 
   failure:
-    free(virBufferContentAndReset(&buffer));
+    if (request == NULL) {
+        request = virBufferContentAndReset(&buffer);
+    }
 
     result = -1;
 
@@ -972,10 +900,10 @@ esxVI_FindByUuid(virConnectPtr conn, esxVI_Context *ctx,
                  esxVI_ManagedObjectReference **managedObjectReference)
 {
     int result = 0;
-    esxVI_RemoteRequest *remoteRequest = NULL;
-    esxVI_RemoteResponse *remoteResponse = NULL;
     char uuid_string[VIR_UUID_STRING_BUFLEN] = "";
     virBuffer buffer = VIR_BUFFER_INITIALIZER;
+    char *request = NULL;
+    esxVI_Response *response = NULL;
 
     if (ctx->service == NULL) {
         ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid call");
@@ -992,8 +920,7 @@ esxVI_FindByUuid(virConnectPtr conn, esxVI_Context *ctx,
     virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
     virBufferAddLit(&buffer, "<FindByUuid xmlns=\"urn:vim25\">");
 
-    if (esxVI_RemoteRequest_Alloc(conn, &remoteRequest) < 0 ||
-        esxVI_ManagedObjectReference_Serialize(conn, ctx->service->searchIndex,
+    if (esxVI_ManagedObjectReference_Serialize(conn, ctx->service->searchIndex,
                                                "_this", &buffer,
                                                esxVI_Boolean_True) < 0 ||
         esxVI_ManagedObjectReference_Serialize(conn, datacenter,
@@ -1014,35 +941,28 @@ esxVI_FindByUuid(virConnectPtr conn, esxVI_Context *ctx,
         goto failure;
     }
 
-    remoteRequest->request = virBufferContentAndReset(&buffer);
-    remoteRequest->xpathExpression =
-      ESX_VI__SOAP__RESPONSE_XPATH("FindByUuid");
+    request = virBufferContentAndReset(&buffer);
 
-    if (esxVI_RemoteRequest_Execute(conn, ctx, remoteRequest, &remoteResponse,
-                                    esxVI_Boolean_False) < 0 ||
+    if (esxVI_Context_Execute(conn, ctx, request,
+                              ESX_VI__SOAP__RESPONSE_XPATH("FindByUuid"),
+                              &response, esxVI_Boolean_False) < 0 ||
         esxVI_ManagedObjectReference_Deserialize
-          (conn, remoteResponse->node, managedObjectReference,
+          (conn, response->node, managedObjectReference,
            vmSearch == esxVI_Boolean_True ? "VirtualMachine"
                                           : "HostSystem") < 0) {
         goto failure;
     }
 
   cleanup:
-    /*
-     * Remove static values from the data structures to prevent them from
-     * being freed by the call to esxVI_RemoteRequest_Free().
-     */
-    if (remoteRequest != NULL) {
-        remoteRequest->xpathExpression = NULL;
-    }
-
-    esxVI_RemoteRequest_Free(&remoteRequest);
-    esxVI_RemoteResponse_Free(&remoteResponse);
+    VIR_FREE(request);
+    esxVI_Response_Free(&response);
 
     return result;
 
   failure:
-    free(virBufferContentAndReset(&buffer));
+    if (request == NULL) {
+        request = virBufferContentAndReset(&buffer);
+    }
 
     result = -1;
 
@@ -1059,9 +979,9 @@ esxVI_QueryAvailablePerfMetric(virConnectPtr conn, esxVI_Context *ctx,
                                esxVI_PerfMetricId **perfMetricIdList)
 {
     int result = 0;
-    esxVI_RemoteRequest *remoteRequest = NULL;
-    esxVI_RemoteResponse *remoteResponse = NULL;
     virBuffer buffer = VIR_BUFFER_INITIALIZER;
+    char *request = NULL;
+    esxVI_Response *response = NULL;
 
     if (ctx->service == NULL) {
         ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid call");
@@ -1076,8 +996,7 @@ esxVI_QueryAvailablePerfMetric(virConnectPtr conn, esxVI_Context *ctx,
     virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
     virBufferAddLit(&buffer, "<QueryAvailablePerfMetric xmlns=\"urn:vim25\">");
 
-    if (esxVI_RemoteRequest_Alloc(conn, &remoteRequest) < 0 ||
-        esxVI_ManagedObjectReference_Serialize(conn, ctx->service->perfManager,
+    if (esxVI_ManagedObjectReference_Serialize(conn, ctx->service->perfManager,
                                                "_this", &buffer,
                                                esxVI_Boolean_True) < 0 ||
         esxVI_ManagedObjectReference_Serialize(conn, entity,
@@ -1100,33 +1019,26 @@ esxVI_QueryAvailablePerfMetric(virConnectPtr conn, esxVI_Context *ctx,
         goto failure;
     }
 
-    remoteRequest->request = virBufferContentAndReset(&buffer);
-    remoteRequest->xpathExpression =
-      ESX_VI__SOAP__RESPONSE_XPATH("QueryAvailablePerfMetric");
+    request = virBufferContentAndReset(&buffer);
 
-    if (esxVI_RemoteRequest_Execute(conn, ctx, remoteRequest, &remoteResponse,
-                                    esxVI_Boolean_True) < 0 ||
-        esxVI_PerfMetricId_DeserializeList(conn, remoteResponse->node,
+    if (esxVI_Context_Execute(conn, ctx, request,
+                              ESX_VI__SOAP__RESPONSE_XPATH("QueryAvailablePerfMetric"),
+                              &response, esxVI_Boolean_True) < 0 ||
+        esxVI_PerfMetricId_DeserializeList(conn, response->node,
                                            perfMetricIdList) < 0) {
         goto failure;
     }
 
   cleanup:
-    /*
-     * Remove static values from the data structures to prevent them from
-     * being freed by the call to esxVI_RemoteRequest_Free().
-     */
-    if (remoteRequest != NULL) {
-        remoteRequest->xpathExpression = NULL;
-    }
-
-    esxVI_RemoteRequest_Free(&remoteRequest);
-    esxVI_RemoteResponse_Free(&remoteResponse);
+    VIR_FREE(request);
+    esxVI_Response_Free(&response);
 
     return result;
 
   failure:
-    free(virBufferContentAndReset(&buffer));
+    if (request == NULL) {
+        request = virBufferContentAndReset(&buffer);
+    }
 
     result = -1;
 
@@ -1141,9 +1053,9 @@ esxVI_QueryPerfCounter(virConnectPtr conn, esxVI_Context *ctx,
                        esxVI_PerfCounterInfo **perfCounterInfoList)
 {
     int result = 0;
-    esxVI_RemoteRequest *remoteRequest = NULL;
-    esxVI_RemoteResponse *remoteResponse = NULL;
     virBuffer buffer = VIR_BUFFER_INITIALIZER;
+    char *request = NULL;
+    esxVI_Response *response = NULL;
 
     if (ctx->service == NULL) {
         ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid call");
@@ -1158,8 +1070,7 @@ esxVI_QueryPerfCounter(virConnectPtr conn, esxVI_Context *ctx,
     virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
     virBufferAddLit(&buffer, "<QueryPerfCounter xmlns=\"urn:vim25\">");
 
-    if (esxVI_RemoteRequest_Alloc(conn, &remoteRequest) < 0 ||
-        esxVI_ManagedObjectReference_Serialize(conn, ctx->service->perfManager,
+    if (esxVI_ManagedObjectReference_Serialize(conn, ctx->service->perfManager,
                                                "_this", &buffer,
                                                esxVI_Boolean_True) < 0 ||
         esxVI_Int_SerializeList(conn, counterIdList, "counterId", &buffer,
@@ -1175,33 +1086,26 @@ esxVI_QueryPerfCounter(virConnectPtr conn, esxVI_Context *ctx,
         goto failure;
     }
 
-    remoteRequest->request = virBufferContentAndReset(&buffer);
-    remoteRequest->xpathExpression =
-      ESX_VI__SOAP__RESPONSE_XPATH("QueryPerfCounter");
+    request = virBufferContentAndReset(&buffer);
 
-    if (esxVI_RemoteRequest_Execute(conn, ctx, remoteRequest, &remoteResponse,
-                                    esxVI_Boolean_True) < 0 ||
-        esxVI_PerfCounterInfo_DeserializeList(conn, remoteResponse->node,
+    if (esxVI_Context_Execute(conn, ctx, request,
+                              ESX_VI__SOAP__RESPONSE_XPATH("QueryPerfCounter"),
+                              &response, esxVI_Boolean_True) < 0 ||
+        esxVI_PerfCounterInfo_DeserializeList(conn, response->node,
                                               perfCounterInfoList) < 0) {
         goto failure;
     }
 
   cleanup:
-    /*
-     * Remove static values from the data structures to prevent them from
-     * being freed by the call to esxVI_RemoteRequest_Free().
-     */
-    if (remoteRequest != NULL) {
-        remoteRequest->xpathExpression = NULL;
-    }
-
-    esxVI_RemoteRequest_Free(&remoteRequest);
-    esxVI_RemoteResponse_Free(&remoteResponse);
+    VIR_FREE(request);
+    esxVI_Response_Free(&response);
 
     return result;
 
   failure:
-    free(virBufferContentAndReset(&buffer));
+    if (request == NULL) {
+        request = virBufferContentAndReset(&buffer);
+    }
 
     result = -1;
 
@@ -1216,9 +1120,9 @@ esxVI_QueryPerf(virConnectPtr conn, esxVI_Context *ctx,
                 esxVI_PerfEntityMetric **perfEntityMetricList)
 {
     int result = 0;
-    esxVI_RemoteRequest *remoteRequest = NULL;
-    esxVI_RemoteResponse *remoteResponse = NULL;
     virBuffer buffer = VIR_BUFFER_INITIALIZER;
+    char *request = NULL;
+    esxVI_Response *response = NULL;
 
     if (ctx->service == NULL) {
         ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid call");
@@ -1233,13 +1137,11 @@ esxVI_QueryPerf(virConnectPtr conn, esxVI_Context *ctx,
     virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
     virBufferAddLit(&buffer, "<QueryPerf xmlns=\"urn:vim25\">");
 
-    if (esxVI_RemoteRequest_Alloc(conn, &remoteRequest) < 0 ||
-        esxVI_ManagedObjectReference_Serialize(conn, ctx->service->perfManager,
+    if (esxVI_ManagedObjectReference_Serialize(conn, ctx->service->perfManager,
                                                "_this", &buffer,
                                                esxVI_Boolean_True) < 0 ||
         esxVI_PerfQuerySpec_SerializeList(conn, querySpecList, "querySpec",
-                                          &buffer,
-                                          esxVI_Boolean_True) < 0) {
+                                          &buffer, esxVI_Boolean_True) < 0) {
         goto failure;
     }
 
@@ -1251,32 +1153,26 @@ esxVI_QueryPerf(virConnectPtr conn, esxVI_Context *ctx,
         goto failure;
     }
 
-    remoteRequest->request = virBufferContentAndReset(&buffer);
-    remoteRequest->xpathExpression = ESX_VI__SOAP__RESPONSE_XPATH("QueryPerf");
+    request = virBufferContentAndReset(&buffer);
 
-    if (esxVI_RemoteRequest_Execute(conn, ctx, remoteRequest, &remoteResponse,
-                                    esxVI_Boolean_True) < 0 ||
-        esxVI_PerfEntityMetric_DeserializeList(conn, remoteResponse->node,
+    if (esxVI_Context_Execute(conn, ctx, request,
+                              ESX_VI__SOAP__RESPONSE_XPATH("QueryPerf"),
+                              &response, esxVI_Boolean_True) < 0 ||
+        esxVI_PerfEntityMetric_DeserializeList(conn, response->node,
                                                perfEntityMetricList) < 0) {
         goto failure;
     }
 
   cleanup:
-    /*
-     * Remove static values from the data structures to prevent them from
-     * being freed by the call to esxVI_RemoteRequest_Free().
-     */
-    if (remoteRequest != NULL) {
-        remoteRequest->xpathExpression = NULL;
-    }
-
-    esxVI_RemoteRequest_Free(&remoteRequest);
-    esxVI_RemoteResponse_Free(&remoteResponse);
+    VIR_FREE(request);
+    esxVI_Response_Free(&response);
 
     return result;
 
   failure:
-    free(virBufferContentAndReset(&buffer));
+    if (request == NULL) {
+        request = virBufferContentAndReset(&buffer);
+    }
 
     result = -1;