How to add WMS services as background? All services I try end with "Map layer validation failed for URL" error.Is it because of CORS?
Hi Oto. Can you share some of the URLs you have tried?
Give this one a try, you'll need to zoom out and view Australia.
Yours works but not mine.
For example this even having EPSG:3857:https://www.gisnet.lv/cgi-bin/topo?service=wms&request=GetCapabilities
Hi Oto, I have tried to access your URL and by hitting F12 to launch the developer console, I can confirm that it is a CORS policy problem.You need to configure (whitelist) your WMS server to accept the URLs coming from the Bentley App you use to access your iModels:
For the Bentley CONNECT portal:
If you launch through the iTwin Design Review Hub, this address must be added:
If you launch it through the iTwin Hub, this address must be added:
Then this renders this feature unusable if public and opendata WMS can't be used. Then why Ron example works?
Hi. No, I don't believe that statement to be true. Ron's example works because that server supports CORS. When the browser sends the Origin: header, the response contains a proper Access-Control-Allow-Origin response. That satisfies the browser's concerns about CORS. When presented with an Origin: header, your WMS server does not provide a Access-Control-Allow-Origin response. The browser takes this as a refusal from your server to respond to this particular request. CORS is a protection mechanism against malicious web pages that would do cross-domain requests without your consent. Bentley did not invent this. I suggest you look at document on the internet, like this one for example: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS .
Making a (WMS) web server public simply means making it CORS-compliant and whitelisting the proper origins, or "*" in the case of a public site.
Your server will work fine as it is today when it's called directly, or from another executable program. Only web browsers apply CORS rules. iTwin applications like Design Review are web applications and as such are bound to respect the CORS rules. We have built our WMS and in general map layers support so that requests are made from your browser instead of going through another Bentley cloud service first. Although that would have removed the CORS problem, it would have slowed down each request. More importantly, it would have prevented access to on-premise WMS or Esri REST services when they are not accessible publicly. The current solution supports both on-premise private servers as well as public services, as long as CORS is configured.
Hope this helps.