Function: soap-encode-body

soap-encode-body is a byte-compiled function defined in soap-client.el.gz.

Signature

(soap-encode-body OPERATION PARAMETERS &optional SERVICE-URL)

Documentation

Create the body of a SOAP request for OPERATION in the current buffer.

PARAMETERS is a list of parameters supplied to the OPERATION.

The OPERATION and PARAMETERS are encoded according to the WSDL document. SERVICE-URL should be provided when WS-Addressing is being used.

Source Code

;; Defined in /usr/src/emacs/lisp/net/soap-client.el.gz
(defun soap-encode-body (operation parameters &optional service-url)
  "Create the body of a SOAP request for OPERATION in the current buffer.
PARAMETERS is a list of parameters supplied to the OPERATION.

The OPERATION and PARAMETERS are encoded according to the WSDL
document.  SERVICE-URL should be provided when WS-Addressing is
being used."
  (let* ((op (soap-bound-operation-operation operation))
         (use (soap-bound-operation-use operation))
         (message (cdr (soap-operation-input op)))
         (parameter-order (soap-operation-parameter-order op))
         (param-table (cl-loop for formal in parameter-order
                               for value in parameters
                               collect (cons formal value))))

    (unless (= (length parameter-order) (length parameters))
      (error "Wrong number of parameters for %s: expected %d, got %s"
             (soap-element-name op)
             (length parameter-order)
             (length parameters)))

    (let ((headers (soap-bound-operation-soap-headers operation))
          (input-action (soap-operation-input-action op)))
      (when headers
        (insert "<soap:Header>\n")
        (when input-action
          (add-to-list 'soap-encoded-namespaces "wsa")
          (insert "<wsa:Action>" input-action "</wsa:Action>\n")
          (insert "<wsa:To>" service-url "</wsa:To>\n"))
        (dolist (h headers)
          (let* ((message (nth 0 h))
                 (part (assq (nth 1 h) (soap-message-parts message)))
                 (value (cdr (assoc (car part) (car parameters))))
                 (use (nth 2 h))
                 (element (cdr part)))
            (when (eq use 'encoded)
              (when (soap-element-namespace-tag element)
                (add-to-list 'soap-encoded-namespaces
                             (soap-element-namespace-tag element)))
              (insert "<" (soap-element-fq-name element) ">\n"))
            (soap-encode-value value element)
            (when (eq use 'encoded)
              (insert "</" (soap-element-fq-name element) ">\n"))))
        (insert "</soap:Header>\n")))

    (insert "<soap:Body>\n")
    (when (eq use 'encoded)
      (when (soap-element-namespace-tag op)
        (add-to-list 'soap-encoded-namespaces (soap-element-namespace-tag op)))
      (insert "<" (soap-element-fq-name op) ">\n"))

    (dolist (part (soap-message-parts message))
      (let* ((param-name (car part))
             (element (cdr part))
             (value (cdr (assoc param-name param-table))))
        (when (or (null (soap-bound-operation-soap-body operation))
                  (member param-name
                          (soap-bound-operation-soap-body operation)))
          (soap-encode-value value element))))

    (when (eq use 'encoded)
      (insert "</" (soap-element-fq-name op) ">\n"))
    (insert "</soap:Body>\n")))