# Wms Custom Provider

**URL:** <https://mapwindow.discourse.group/t/wms-custom-provider/467>\
**Category:** MapWinGIS\
**Created:** [February 24, 2020, 8:35am UTC](https://mapwindow.discourse.group/t/wms-custom-provider/467 "2020-02-24T08:35:53Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![mcanitez](https://avatars.discourse-cdn.com/v4/letter/m/a87d85/32.png) [@mcanitez](https://mapwindow.discourse.group/u/mcanitez)\
**Post date:** [February 24, 2020, 8:35am UTC](https://mapwindow.discourse.group/t/wms-custom-provider/467/1 "2020-02-24T08:35:53Z")

</div>

Hi,

I’m developing a windows form application with c # and I want to use mapwingis custom provider Wms.  
I have reviewed your documents, but could not find how to import a wms service.There are some Code samples and I implemented them but I couldn’t provide the image.

Sample Wms Service

> **[GEBCO - The General Bathymetric Chart of the Oceans](https://www.gebco.net/)**
>
> The General Bathymetric Chart of the Oceans (GEBCO) aims to provide the most authoritative, publicly available bathymetry data sets for the world’s oceans.

and my sample code

> <https://gis.stackexchange.com/questions/289051/loading-wms-layer-with-mapwingis-from-geoserver>

and exception

{“Exception of type ‘System.Windows.Forms.AxHost+InvalidActiveXStateException’ was thrown.”}

How can i solve this problem and what is your suggestion.

Thank you

---

<div class="post-metadata">

**Author:** ![jerryfaust](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/jerryfaust/32/378_2.png) [@jerryfaust](https://mapwindow.discourse.group/u/jerryfaust)\
**Post date:** [February 25, 2020, 10:45pm UTC](https://mapwindow.discourse.group/t/wms-custom-provider/467/2 "2020-02-25T22:45:43Z")

</div>

Hello @mcanitez

The exception does not specifically have to do with the WMS layer, but with the OCX. You are instantiating the OCX inline rather than adding it as a control to your main form.

To verify, I pasted your code into an app that does not have the OCX loaded onto the form (in the Designer), and tried to load a JPG, and I get the same exception.

You should remove your declaration of axMap (`AxMap axMap = new AxMap();`) and instead add the OCX to your form, it will generate an axMap1 variable. You then can add your layers to that map reference, and it should work properly.

Regards,  
Jerry.

---

<div class="post-metadata">

**Author:** ![mcanitez](https://avatars.discourse-cdn.com/v4/letter/m/a87d85/32.png) [@mcanitez](https://mapwindow.discourse.group/u/mcanitez)\
**Post date:** [February 26, 2020, 7:33am UTC](https://mapwindow.discourse.group/t/wms-custom-provider/467/3 "2020-02-26T07:33:55Z")

</div>

Thank you for the help.I apply the sample code but I always see the openstreetmap map

 ![sample_map](https://global.discourse-cdn.com/free1/uploads/mapwindow1/original/1X/166f0d1c62c148ec697505f776c99ee26a430192.png)

![sample_Code](https://global.discourse-cdn.com/free1/uploads/mapwindow1/original/1X/0d9257eceb291494b0b265f333af812c1be2cfdb.png)

I keep getting the same result even though I write different urls.I do not understand how to add custom provider.

---

<div class="post-metadata">

**Author:** ![jerryfaust](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/jerryfaust/32/378_2.png) [@jerryfaust](https://mapwindow.discourse.group/u/jerryfaust)\
**Post date:** [February 27, 2020, 8:10pm UTC](https://mapwindow.discourse.group/t/wms-custom-provider/467/4 "2020-02-27T20:10:39Z")

</div>

Hello @mcanitez

You can add a custom provider via the [TileProviders.Add](https://www.mapwindow.org/documentation/mapwingis4.9/class_tile_providers.html#abdcf585bfba3167799762158b1fced13) method.

Here’s a simple example that sets Open Street Maps as a custom provider.

```
// add definition of custom provider
int newID = (int)tkTileProvider.ProviderCustom;
axMap1.Tiles.Providers.Add(newID, "Custom Provider",
    "https://{switch:a,b,c}.tile.openstreetmap.org/{zoom}/{x}/{y}.png",
    tkTileProjection.SphericalMercator, 0, 18);
// set custom provider as the current provider
axMap1.Tiles.ProviderId = newID;
axMap1.Redraw3(tkRedrawType.RedrawSkipAllLayers, true);

```

Regards,  
Jerry.

Addendum: you can find [more information here](https://www.mapwindow.org/documentation/mapwingis4.9/class_tiles.html#details), scrolling down for examples and explanations of custom providers.

---

<div class="post-metadata">

**Author:** ![mcanitez](https://avatars.discourse-cdn.com/v4/letter/m/a87d85/32.png) [@mcanitez](https://mapwindow.discourse.group/u/mcanitez)\
**Post date:** [June 30, 2020, 5:58pm UTC](https://mapwindow.discourse.group/t/wms-custom-provider/467/5 "2020-06-30T17:58:51Z")

</div>

Hi,  
I realize it’s been a long time. Thank you for the answer. I wrote code as you told.  
I just added as much authorization code as I described. I do not know if this method is correct. When I run it in this state, nothing appears on the screen. I got the image with a different component but I want to use mapwingis. I am aware that I am doing something missing. I’m waiting for your help.

[image]

 ![image](https://global.discourse-cdn.com/free1/uploads/mapwindow1/original/1X/00b2c23f06f0bca29458c809a4205dfc2596d09f.png)

---

<div class="post-metadata">

**Author:** ![jerryfaust](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/jerryfaust/32/378_2.png) [@jerryfaust](https://mapwindow.discourse.group/u/jerryfaust)\
**Post date:** [July 1, 2020, 6:20pm UTC](https://mapwindow.discourse.group/t/wms-custom-provider/467/6 "2020-07-01T18:20:21Z")

</div>

Hello @mcanitez

I really know nothing about WMS layers, but I think it is more likely you should be using the WMSLayer class rather than setting up a custom provider, since I don’t think a WMS server is a Tile Provider. Perhaps someone else has some knowledge in this area? (@pmeems, do you know more about this?)

---

<div class="post-metadata">

**Author:** ![pmeems](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/pmeems/32/9_2.png) [@pmeems](https://mapwindow.discourse.group/u/pmeems)\
**Post date:** [July 2, 2020, 6:23am UTC](https://mapwindow.discourse.group/t/wms-custom-provider/467/7 "2020-07-02T06:23:43Z")

</div>

@jerryfaust is right. You cannot use the Tile provider, which is doing a TMS request to use with WMS.  
Those are two different protocols.  
The [WMS Layer](https://www.mapwindow.org/documentation/mapwingis4.9/class_wms_layer.html) is the way to go.

---

<div class="post-metadata">

**Author:** ![mcanitez](https://avatars.discourse-cdn.com/v4/letter/m/a87d85/32.png) [@mcanitez](https://mapwindow.discourse.group/u/mcanitez)\
**Post date:** [July 8, 2020, 12:09pm UTC](https://mapwindow.discourse.group/t/wms-custom-provider/467/8 "2020-07-08T12:09:10Z")

</div>

Thanks for the answer. So how can I solve this. I have reviewed the document but have not found a complete solution. What do I need to do to view custom wms and add authorization. Can you send an example.

---

<div class="post-metadata">

**Author:** ![pmeems](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/pmeems/32/9_2.png) [@pmeems](https://mapwindow.discourse.group/u/pmeems)\
**Post date:** [July 24, 2020, 7:31am UTC](https://mapwindow.discourse.group/t/wms-custom-provider/467/9 "2020-07-24T07:31:04Z")

</div>

I haven’t used the [WMS Layer](https://www.mapwindow.org/documentation/mapwingis4.9/class_wms_layer.html) myself and the documentation doesn’t have anything about how to add authorization.

You could also create a GDAL WMS XML file and load it as a layer. I have no experience with this either, but in their [documentation](https://gdal.org/drivers/raster/wms.html) I see room for username and password.

---

<div class="post-metadata">

**Author:** ![pmeems](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/pmeems/32/9_2.png) [@pmeems](https://mapwindow.discourse.group/u/pmeems)\
**Post date:** [January 5, 2022, 3:09pm UTC](https://mapwindow.discourse.group/t/wms-custom-provider/467/10 "2022-01-05T15:09:03Z")

</div>


