Explainer
Why an S7-1500 OPC UA server publishes each UDT twice
Short answer
The S7-1500 OPC UA server publishes the same UDT in two namespaces: a string-NodeId entry from the standard SIMATIC interface and a numeric-NodeId entry from a custom Server Interface. OPC UA treats them as two distinct types that share a browse name, and each variable's DataType attribute names the one that counts. Resolve the type and binary-encoding ids at session start from what the variable declares, and keep the ids out of generated codecs.

On this page
- Two namespaces make two distinct types
- The variable's DataType attribute is the authority
- Why the numeric ids move after every project download
- Resolve type and encoding ids at session start
- Worked example: one PumpUDT variable from dump to decode
- What to verify after the change
- The decision
- Questions asked
Each duplicate entry is the S7-1500 publishing the same UDT in two namespaces: one entry carries a string NodeId from the CPU's standard SIMATIC interface, the other a numeric NodeId from a custom Server Interface created in the project. Under the OPC UA rules these are two distinct types that merely share a browse name, and each variable's DataType attribute names the one that actually travels on the wire — in the installation examined here, the numeric one. The duplicate is therefore project configuration, not a client defect. The fix is to stop hard-coding type and binary-encoding ids in generated codec classes and resolve them once per session, from the DataType attribute each variable reports.
Two namespaces make two distinct types #
IEC 62541, the OPC UA specification, qualifies every NodeId and every BrowseName with a namespace index: a node's identity is the pair of namespace index and identifier, so the same identifier string under two indexes names two different nodes. The specification defines no rule that merges types sharing a browse name across namespaces. A client builds its type tree by browsing the standard BaseDataType node (i=24) and following subtype references, so every Structure subtype appears no matter which namespace owns it, and any namespace that publishes the UDT adds an independent entry.
On one S7-1500 installation, a UDT named PumpUDT appeared in the client's DataTypeTree as two complete entries. The values below are what that server reported:
| Entry | NodeId | Binary encoding id | Source |
|---|---|---|---|
| PumpUDT in namespace 3 | ns=3; DT_"PumpUDT" |
ns=3; TE_"PumpUDT" |
standard SIMATIC interface |
| PumpUDT in namespace 4 | ns=4; i=2 |
ns=4; i=3 |
a custom Server Interface |
The second namespace comes from the documented Siemens feature called a server interface, which bundles nodes of a CPU's address space into one unit so OPC UA clients get a defined view of that CPU. TIA Portal manages the list under "OPC UA communication > Server interfaces", where "Add new server interface" creates one; the embedded server behind it needs the firmware and TIA Portal baseline covered in S7-1500 OPC UA server firmware requirement: V2.0 and TIA V14.
The standard SIMATIC interface publishes project types with string NodeIds taken from the symbolic UDT names, and each added Server Interface publishes its referenced types in its own namespace with numeric NodeIds assigned when the project loads. If more than one interface references the same UDT, the server publishes it once per interface. That is the whole duplication mechanism, produced in the project, not in the client.
If the type tree never builds at all, the session did not get that far and the cause is a connection, certificate or security setting; those failure modes are covered in Troubleshooting an S7-1500 OPC UA client that cannot connect.
Which interface owns the variable #
- Connect a generic client such as UaExpert to the same endpoint and browse DataTypes, BaseDataType, Structure; locate both entries for the UDT.
- For each entry, read the namespace URI behind the index from the server's namespace array, so the binding names the interface and not just a number.
- Select the process variable and read its DataType attribute; record whether it points at the string id or the numeric id.
- In TIA Portal, open "OPC UA communication > Server interfaces" for the CPU and match the interface that contains the tag or DB, and the interfaces that reference the UDT, to the namespaces recorded above.
- Compare the DataTypeDefinition attribute of both DataType nodes: field names, order and types. Identical definitions mean the two types carry the same byte layout; different definitions mean only the declared type decodes the value.
The variable's DataType attribute is the authority #
Each entry is a real type with its own encoding. Every DataType node carries a forward HasEncoding reference (i=38) to a Default Binary encoding object, and each encoding points back to its own DataType; nothing links the namespace-3 pair to the namespace-4 pair except the shared browse name.
What a subscription delivers is decided by the variable, not by the client. The DataType attribute on a UDT variable names exactly one of the two entries, and in the installation examined here getDataType() returned the numeric id, so the ExtensionObjects on the wire carry the numeric binary encoding. A codec registered under the string encoding id can never fire: its key does not match the id on the wire, while the numeric encoding arrives with nothing registered under it and the subscription hands out raw undecoded bytes. No client setting overrides the attribute — it is the same authority that fails an OPC UA Int16 write whose payload is a string, as covered in Why an OPC UA Int16 write fails when the payload is a string.
Why the numeric ids move after every project download #
String NodeIds follow the symbolic UDT name, so the string pair survives every download unchanged. Numeric NodeIds are assigned when the project loads, and one reported installation saw a download renumber them even for UDTs whose definition had not changed. A codegen tool that bakes ids into each codec class therefore churns on every hardware download: that installation committed roughly 200 generated files per project update, because every class carried its own TYPE_ID and BINARY_ENCODING_ID constants for ids the UDT itself does not control.
Separate what a codec is from what the server calls it. The class layout — field names, order, types — changes only when the UDT changes; the ids change when the server renumbers. Generate the classes from the structure definition alone, key them by browse name, and treat the resolved ids as runtime state: log the table the client bound at session start instead of committing it. If constants are still generated for offline reference, isolate them in one small file so a renumbering touches one file instead of 200.
Resolve type and encoding ids at session start #
Build the registration around what each variable declares, not around a pre-computed id pair. That removes the name-to-id map and the reference-fixing loop from the tooling:
- For every variable in the subscription list, read the DataType attribute once after the session is open.
- Carry it as an ExpandedNodeId with the namespace URI, so a namespace-index change cannot invalidate the binding.
- Look that data type up in the client's data type tree and read the binaryEncodingId it reports; that is the id the server will put in every ExtensionObject for the variable.
- Select the codec by the UDT's browse name reached through that data type. Matching the name is safe here because the variable itself points at this data type; it is not a guess across every node sharing the name.
- Register the codec with the client's data type manager under the resolved data type id and the resolved binary encoding id. Keep the startup validator that compares generated constants against the server, but make the server id win every time, so the fallback becomes the only path.
Worked example: one PumpUDT variable from dump to decode #
The ids are the values from the table above; the variable is any tag of type PumpUDT. Five checks take it from dump to decoded object:
- Read the DataType attribute on the variable: it returns
ns=4; i=2, so the string id never enters the binding. - The tree lookup of that id returns binaryEncodingId
ns=4; i=3. - Register the codec with the client's data type manager under both resolved ids, data type and binary encoding, as read in the two steps above.
- The first subscription notification arrives with an ExtensionObject whose type id is
ns=4; i=3. It equals the registration key, so the codec fires and returns the generated PumpUDT object with all fields decoded. - The old failure, for contrast: a codec registered under the string encoding
ns=3; TE_"PumpUDT"never matches, because the wire type idns=4; i=3and that key differ in both namespace index and identifier. The client logs codec-not-found and delivers a raw ExtensionObject.
What to verify after the change #
- Dump the data type tree after connecting: both entries still appear for each UDT. Runtime resolution does not remove the duplicates, and the code must not depend on their absence.
- Read the DataType attribute on one subscribed variable, follow it to its binary encoding id in the tree, and compare with the key used at registration: the two must be equal.
- Subscribe and read one value: it decodes into the generated class, with no codec-not-found warning and no raw bytes left over.
- Have a project downloaded with at least one UDT unchanged, then restart the client without regenerating code: the unchanged UDT still decodes, because the binding followed the renumbered ids.
- Run the code generator twice against the same project and diff the output: the classes must come out byte-identical, since no id is embedded in them.
The decision #
- Two entries under one browse name: expected output of this server configuration, and every conforming client sees both. Do not merge them in the client and do not treat the second entry as a parsing artifact.
- Codec never fires on subscriptions: it is keyed to the string encoding while the variable declares the numeric type. Rebind at session start from the DataType attribute; the first decoded notification is the proof.
- Ids churn after every download: keep generated codecs id-free, resolve the ids at runtime, and let the server's ids win over generated constants.
- String ids wanted on the wire: the id style belongs to the interface that publishes the type, and the variable's DataType attribute decides what decodes. If the string view matters, publish the variable through the interface that uses string ids and confirm the DataType attribute follows before relying on it.
Questions asked
Is the duplicate a bug in my client library?
No. The two entries are independent nodes the server created, so every conforming client, in any library or language, sees both. A client that merges them by browse name decodes the wrong encoding as soon as a variable declares the other type. Treat the duplication as a fact of this server configuration and bind to what each variable declares.
Can the duplicate be removed instead of resolved?
Only on the server side. A namespace disappears when the Server Interface that publishes it is deleted from the CPU's OPC UA settings in TIA Portal, which is only safe when no client depends on that interface's view. For a running system, keep both namespaces and resolve the ids at runtime; that survives every interface change.
Does anything change in Milo 1.x?
The duplicates stay, because they come from the server's address space. What changes in Milo 1.x is client plumbing: the session initializer that attached the data type tree to a session is reported deprecated in the 1.x migration notes. Port the tree lookup to the 1.x equivalent and keep the same resolution logic; the ids still come from each variable's DataType attribute.
Where does the client get the namespace URI?
From the server's namespace array, the standard table that maps every namespace index to its URI. Read it once after connecting and use the URI, not the index, when you build the ExpandedNodeId for a resolved id. A firmware update or project edit that shifts index numbers then cannot silently point a registration at the wrong namespace.

