# SOAP Client

> 调用 SOAP Web 服务。

Source: https://docs.sommatic.ai/zh/nodes/io.soap/

- 标识: `io.soap`
- 类别: 输入与输出
- 版本: 1.0.0
- 状态: 可用
- 执行方式: async

调用 SOAP Web 服务。

## 配置

- `connection_id` (string, 必填): SOAP 端点/WSDL 的凭据。接受 `basic-auth`（用户名 + 密码）或 `object`（WSDL URL + 高级配置）类型的凭据。
- `method` (string, 必填)
- `args` (object, 可选)

## 输出端口

- `out` (默认): SOAP 响应
- `error`: SOAP fault 或错误

## 输入契约

- `connection_id` (string, 必填)
- `method` (string, 必填)
- `args` (object, 可选)

## 输出契约

- `result` (object, 可选): SOAP 结果

## 在表达式中

后续节点可通过 `$("SOAP Client").item.json.<路径>` 读取此节点输出中的内容（请把 `SOAP Client` 换成你的节点标签）。**Editor** 标记工作流编辑器在 Previous Nodes 中提示的路径（输出契约）；**Worker** 标记 worker 实际通过 `out` 返回的路径，依据“端口”一节所示的输出。

- `$("SOAP Client").item.json.result` (object) = `{…}`: SOAP 结果
- `$("SOAP Client").item.json.result.GetQuoteResult` (object) = `{…}` (编辑器不提示)


## 工作原理

从凭据加载 WSDL，使用 `args` 调用一个 SOAP 操作，并返回解析后的结果对象。

1. 解析配置。`connection_id`、`method` 和 `args`（默认 `{}`）缺失时回退到输入 payload 中的同名键；`connection_id` 和 `method` 为必填。
2. 解析凭据：WSDL URL 为 `config.wsdl`（或 `config.url`）；`username`、`password` 和 `token` 取自密钥。
3. 下载 WSDL 并构建客户端。存在 `username` 和 `password` 时设置 HTTP Basic 安全；否则若存在 `token`，则设置 Bearer 安全。
4. 以 `args` 调用 `method` 操作，并以 `{ result }` 从 `out` 返回响应的第一个元素（解析后的结果对象）。

## 在工作流中

### 节点

```json
{
  "node_id": "node-get-quote",
  "label": "Get quote",
  "operator_slug": "io.soap",
  "operator_version": "1.0.0",
  "config": {
    "connection_id": "pi-credential-xxxx",
    "method": "GetQuote",
    "args": {
      "Symbol": "{{ $json.symbol }}"
    }
  }
}
```

### Envelope

```json
{
  "ok": true,
  "data": {
    "result": {
      "GetQuoteResult": {
        "Symbol": "ACME",
        "Price": "42.17"
      }
    }
  },
  "port": "out"
}
```

## 输出端口 (代码中的行为)

### `out`

操作返回且没有 SOAP fault。`result` 为转换为 JavaScript 对象的响应正文。

```json
{
  "result": {
    "GetQuoteResult": {
      "Symbol": "ACME",
      "Price": "42.17"
    }
  }
}
```

### `error`

缺少必填字段、无法加载 WSDL、操作不存在，或服务器返回 SOAP fault 或 HTTP 错误。

```json
{
  "error": "Method \"GetQuote\" not found in WSDL"
}
```

## 代码中的行为

- `connection_id`: 接受配置中含 `wsdl`（或 `url`）的 `basic-auth` 或 `object` 凭据。以 `http://`、`https://` 或 `localhost` 开头的值会直接用作 WSDL URL，不带认证。
- `args`: 一个对象，其键为该操作输入消息中的元素名称。

## 错误

| 消息 | 端口 | 原因与处理 |
| --- | --- | --- |
| `WSDL URL not found in connection config` | `error` | 凭据配置中既没有 `wsdl` 也没有 `url`。 |
| `Method "<method>" not found in WSDL` | `error` | WSDL 中没有该名称的操作。请使用 WSDL 中声明的原始操作名。 |
| `<SOAP fault or HTTP error message>` | `error` | 服务器拒绝了调用。请检查 `args` 是否与该操作的输入消息一致。 |
| `method is required` | `error` | 配置和输入 payload 中都没有操作名（凭据缺失时对应 `connection_id is required`）。 |

## 说明与限制

- 每次运行都会下载并解析 WSDL。无超时，也不重试。
- 仅返回解析后的结果，不提供响应的原始 XML 和 SOAP 头。


## 契约（JSON Schema）

### All (`*.definition.js`)

```json
{
  "slug": "io.soap",
  "name": "SOAP Client",
  "category": "io",
  "version": "1.0.0",
  "description": "Make SOAP Web Service calls.",
  "capabilities": [
    "soap",
    "api",
    "xml",
    "legacy"
  ],
  "config_schema": {
    "type": "object",
    "properties": {
      "connection_id": {
        "type": "string",
        "title": "SOAP Credential",
        "description": "Credential for the SOAP endpoint / WSDL. Accepts credentials of type `basic-auth` (username + password) or `object` (WSDL URL + advanced config).",
        "ui_widget": "connection_picker",
        "ui_options": {
          "credential_types": [
            "basic-auth",
            "object"
          ],
          "types": [
            "soap"
          ]
        }
      },
      "method": {
        "type": "string"
      },
      "args": {
        "type": "object"
      }
    },
    "required": [
      "connection_id",
      "method"
    ]
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "connection_id": {
        "type": "string"
      },
      "method": {
        "type": "string"
      },
      "args": {
        "type": "object"
      }
    },
    "required": [
      "connection_id",
      "method"
    ]
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "result": {
        "type": "object",
        "description": "SOAP Result"
      }
    }
  },
  "ports": [
    {
      "port_id": "out",
      "label": "Response",
      "description": "Soap response",
      "is_default": true,
      "supports_condition": true
    },
    {
      "port_id": "error",
      "label": "Error",
      "description": "Soap fault or error",
      "is_default": false,
      "supports_condition": false
    }
  ],
  "execution_mode": "async",
  "required_resources": [],
  "compatible_worker_pools": [
    "standard-io",
    "legacy-io"
  ],
  "tags": [
    "api",
    "legacy"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_link_loom",
    "profile": {
      "name": "Link Loom",
      "verified": true,
      "url": "https://me.veripass.com/link-loom",
      "logo_url": null
    }
  }
}
```

### config_schema

```json
{
  "type": "object",
  "properties": {
    "connection_id": {
      "type": "string",
      "title": "SOAP Credential",
      "description": "Credential for the SOAP endpoint / WSDL. Accepts credentials of type `basic-auth` (username + password) or `object` (WSDL URL + advanced config).",
      "ui_widget": "connection_picker",
      "ui_options": {
        "credential_types": [
          "basic-auth",
          "object"
        ],
        "types": [
          "soap"
        ]
      }
    },
    "method": {
      "type": "string"
    },
    "args": {
      "type": "object"
    }
  },
  "required": [
    "connection_id",
    "method"
  ]
}
```

### input_contract_schema

```json
{
  "type": "object",
  "properties": {
    "connection_id": {
      "type": "string"
    },
    "method": {
      "type": "string"
    },
    "args": {
      "type": "object"
    }
  },
  "required": [
    "connection_id",
    "method"
  ]
}
```

### output_contract_schema

```json
{
  "type": "object",
  "properties": {
    "result": {
      "type": "object",
      "description": "SOAP Result"
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "out",
    "label": "Response",
    "description": "Soap response",
    "is_default": true,
    "supports_condition": true
  },
  {
    "port_id": "error",
    "label": "Error",
    "description": "Soap fault or error",
    "is_default": false,
    "supports_condition": false
  }
]
```
