Function: soap-invoke-internal

soap-invoke-internal is a byte-compiled function defined in soap-client.el.gz.

Signature

(soap-invoke-internal CALLBACK CBARGS WSDL SERVICE OPERATION-NAME &rest PARAMETERS)

Documentation

Implement soap-invoke and soap-invoke-async.

If CALLBACK is non-nil, operate asynchronously, then call CALLBACK as (apply CALLBACK RESPONSE CBARGS), where RESPONSE is the SOAP invocation result. If CALLBACK is nil, operate synchronously. WSDL, SERVICE, OPERATION-NAME and PARAMETERS are as described in soap-invoke.

Source Code

;; Defined in /usr/src/emacs/lisp/net/soap-client.el.gz
(defun soap-invoke-internal (callback cbargs wsdl service operation-name
                                      &rest parameters)
  "Implement `soap-invoke' and `soap-invoke-async'.
If CALLBACK is non-nil, operate asynchronously, then call CALLBACK as (apply
CALLBACK RESPONSE CBARGS), where RESPONSE is the SOAP invocation result.
If CALLBACK is nil, operate synchronously.  WSDL, SERVICE,
OPERATION-NAME and PARAMETERS are as described in `soap-invoke'."
  (let* ((port (soap-find-port wsdl service))
         (operation (soap-find-operation port operation-name)))
    (let ((url-request-method "POST")
          (url-package-name "soap-client.el")
          (url-package-version "1.0")
          (url-request-data
           ;; url-request-data expects a unibyte string already encoded...
           (encode-coding-string
            (soap-create-envelope operation parameters wsdl
                                  (soap-port-service-url port))
            'utf-8))
          (url-mime-charset-string "utf-8;q=1, iso-8859-1;q=0.5")
          (url-http-attempt-keepalives t)
          (url-request-extra-headers
           (list
            (cons "SOAPAction"
                  (concat "\"" (encode-coding-string
                                (soap-bound-operation-soap-action
                                 operation)
                                'utf-8)
                          "\""))
            (cons "Content-Type"
                  "text/xml; charset=utf-8"))))
      (if callback
          (url-retrieve
           (soap-port-service-url port)
           (lambda (status)
             (let ((data-buffer (current-buffer)))
               (unwind-protect
                   (let ((error-status (plist-get status :error)))
                     (if error-status
                         (signal (car error-status) (cdr error-status))
                       (apply callback
                              (soap-parse-envelope
                               (soap-parse-server-response)
                               operation wsdl)
                              cbargs)))
                 ;; Ensure the url-retrieve buffer is not leaked.
                 (and (buffer-live-p data-buffer)
                      (kill-buffer data-buffer))))))
        (let ((buffer (url-retrieve-synchronously
                       (soap-port-service-url port))))
          (condition-case err
              (with-current-buffer buffer
                (if (null url-http-response-status)
                    (error "No HTTP response from server"))
                (if (and soap-debug (> url-http-response-status 299))
                    ;; This is a warning because some SOAP errors come
                    ;; back with a HTTP response 500 (internal server
                    ;; error)
                    (warn "Error in SOAP response: HTTP code %s"
                          url-http-response-status))
                (soap-parse-envelope (soap-parse-server-response)
                                     operation wsdl))
            (soap-error
             ;; Propagate soap-errors -- they are error replies of the
             ;; SOAP protocol and don't indicate a communication
             ;; problem or a bug in this code.
             (signal (car err) (cdr err)))
            (error
             (when soap-debug
               (pop-to-buffer buffer))
             (error (error-message-string err)))))))))