How to add a WMS service to ArcGIS Pro using the SDK

4545
3
09-13-2016 12:21 AM

How to add a WMS service to ArcGIS Pro using the SDK

Adding a WMS service to ArcGIS Pro is very simple and straightforward, but you must know which classes to use. Since the documentation is severely lacking in examples, I thought I'd add it here.

using ArcGIS.Core.CIM;
using ArcGIS.Desktop.Framework.Threading.Tasks;
using ArcGIS.Desktop.Mapping;

// Create a connection to the WMS server
var serverConnection = new CIMInternetServerConnection {URL = "Fill in the URL of the WMS service"};
var connection = new CIMWMSServiceConnection {ServerConnection = serverConnection};

// Add a new layer to the map
await QueuedTask.Run(() => 
{
    var layer = LayerFactory.CreateLayer(connection, MapView.Active.Map);
});‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Adding a WMTS or a WCS works exactly the same way, just alter the type of the connection variable.

Oh, and before anyone asks, Identify on a WMS only works if a geographical coordinate system is used. Projected does not work at this moment (BUG-000099054).

Comments

Greetings Berend,

Thank you for the example, that is very useful.  However, if you were to adjust the code for WMS services that are secure with a username and password, how would you do this? 

Also, is it possible to embed the credentials in the code so that when a user accesses the service they are NOT presented with an authentication window asking for credentials?

Thank you in advance.

Hello!

The ProSnippets:Map Authoring wiki page is where you can find snippets for creating various layers using the Pro API.

Here is a snippet that illustrates how to add a WMS service: 

https://github.com/Esri/arcgis-pro-sdk/wiki/ProSnippets-MapAuthoring#add-a-wms-service

 

@MiguelEduardoParedes  The following snippet below should work for you.  I was not able to test this snippet because I couldn't configure a WMS service that requires user/password credentials, probably because I am using an older version of ArcGIS server.  Upgrading my ArcGIS Server will take a while....

try
{
	// Create a connection to the WMS server
	var serverConnection = new CIMInternetServerConnection 
	{ 
		URL = @"https://sdk5.esri.com/arcgis/services/TestCreditsMap/MapServer/WMSServer",
		User="test",
		Password="test" 
	};
	var connection = new CIMWMSServiceConnection { ServerConnection = serverConnection };

	// Add a new layer to the map
	await QueuedTask.Run(() =>
	{
		var layer = LayerFactory.Instance.CreateLayer(connection, MapView.Active.Map);
	});
}
catch (Exception ex)
{
	MessageBox.Show($@"Error: {ex}");
}

 

Version history
Last update:
‎12-12-2021 03:44 AM
Updated by: