BrowseWithPaging
Browse 只返回 References 列表, 丢弃 ContinuationPoint, 适合"已知子节点不多"场景. 子节点可能超过 1000 (SDK 单页上限) 的节点用 BrowseWithPaging 显式拿到 BrowsePage.
前置阅读
- 续翻分页用 BrowseNext.
签名
public BrowsePage BrowseWithPaging(string nodeId, NodeClass filter = NodeClass.Unspecified);
用法
var page = ua.BrowseWithPaging("ns=2;s=BigFolder");
Console.WriteLine($"Got {page.References.Count} children, more = {page.ContinuationPoint != null}");
if (page.ContinuationPoint != null)
{
var next = ua.BrowseNext(page.ContinuationPoint);
Console.WriteLine($"Next page: {next.References.Count} more children");
}
何时用 Browse vs BrowseWithPaging
| 场景 | API |
|---|---|
| 已知子节点不多, 不关心分页 | Browse(...) |
| 不确定子数, 安全起见 | BrowseWithPaging(...) + 循环 BrowseNext |
| 子节点可能上千的大节点 | BrowseWithPaging(...) 必选 |
| 一次 Browse 多个节点 | BrowseMany(...) (注意当前 BrowseMany 不返回 ContinuationPoint) |
分页的触发条件不是"你有多少子节点", 而是服务端这一口气给了多少: SDK 每页固定请求最多 1000 个引用, 服务端可以给得更少, 只要它留了 ContinuationPoint 就说明还有下一页.
完整模板
不用自己写循环 — SDK 已经内置 BrowseAll, 一行拿到全部:
var all = ua.BrowseAll("ns=2;s=BigFolder"); // 自动续翻到底
它的等价展开 (需要控制翻页节奏 / 提前停时才手写):
public static List<OpcUaReference> Collect(
DarraOpcUa ua,
string nodeId,
NodeClass filter = NodeClass.Unspecified)
{
var all = new List<OpcUaReference>();
var page = ua.BrowseWithPaging(nodeId, filter);
all.AddRange(page.References);
while (page.ContinuationPoint != null)
{
page = ua.BrowseNext(page.ContinuationPoint);
all.AddRange(page.References);
}
return all;
}
BrowseAll 比上面多做两件事: 有 maxPages 上限 (默认 32 页), 翻完后尽力释放服务端续点.