Recognize the URL validation failure
The .NET Client SDK rejects a discovered endpoint when EndpointDescription.EndpointUrl contains literal spaces. The reported exception is: The endpoint url must be a syntatically valid URL. Parametername: endpointUrl. A different client accepting the same address does not make the address syntactically valid; a test client may deliberately tolerate invalid URIs to exercise a nonconforming server.
Identify the responsible component
The discovery class returns the endpoint URL registered by the discovery server and does not replace invalid characters. Therefore, finding a literal space in the returned value points to the server-provided endpoint data, while the .NET client's rejection is the expected validation behavior. Report the malformed endpoint to the server vendor for correction.
| Observation | Engineering conclusion |
|---|---|
| Discovered URL contains a literal space | The endpoint is not a syntactically valid URL; encode each space as %20. |
| .NET Client SDK rejects the endpoint | The client is enforcing URL syntax. |
| Another client connects successfully | That client may tolerate invalid URIs for server testing. |
| Discovery returns the invalid text unchanged | Do not expect discovery to sanitize the registered endpoint. |
Apply the temporary client-side workaround
If the server cannot be corrected immediately, modify the discovered EndpointDescription before initiating the connection:
endpointDescription.EndpointUrl = Uri.EscapeUriString(endpointDescription.EndpointUrl);
This converts the literal spaces to escaped URL characters. Treat it as an interoperability workaround rather than the permanent repair because it alters server-supplied endpoint data inside the client.
Verify syntax and endpoint identity
- Inspect the endpoint returned by discovery and confirm that it contains no literal spaces after escaping.
- Confirm that each original space appears as
%20in the connection URL. - Retry the connection with the modified
EndpointDescriptionand verify that URL validation no longer raises the reported exception. - Check the endpoint identity against the URI in the server certificate. A syntax-correct address alone does not establish that the certificate and endpoint description identify the same server.
- After the server vendor corrects the registered endpoint, repeat discovery and remove the client-side rewrite once the returned URL is valid.
FAQ
Why does the .NET OPC UA client reject an endpoint URL with spaces?
Literal spaces are not valid inside the URL. Replace them with %20, preferably by correcting the endpoint registered by the server.
Does OPC UA discovery escape invalid endpoint URL characters?
No. In the described behavior, the discovery class returns the registered endpoint unchanged and does not replace spaces or other invalid characters.
How can I temporarily connect to an OPC UA endpoint containing spaces?
Before connecting, assign Uri.EscapeUriString(endpointDescription.EndpointUrl) back to endpointDescription.EndpointUrl. Then verify the escaped URL and check its identity against the URI in the server certificate.