MVC WMS Server, Adding a WMSLayer and when it tries to recover the capabilities it gets an unauthorised

Topics: SharpMap v2.0
Jan 5, 2014 at 8:23 PM
I have been following the How To guide on how to add a WMS Layer. When I try and create a layer it requires the URL of the WMS Server. No matter what I put in, it always comes back:

"Could not download capabilities document from the server. The server may not be available right now.The remote server returned an error: (401) Unauthorized."

The code I am using is:
       SharpMap.Layers.WmsLayer WMSlayer = new SharpMap.Layers.WmsLayer("WMSOS250","http://localhost:65105/wms/index");
        WMSlayer.AddLayer("OS250");
        WMSlayer.SRID = 27700;

        WMSlayer.SetImageFormat("image/png");
        WMSlayer.ContinueOnError = true;
        WMSlayer.TimeOut = 5000;



        var map = (SharpMap.Map)HttpContext.Application["Map"];
        map.Layers.Add(WMSlayer);
If I navigate to http://localhost:65105/wms/index?REQUEST=GetCapabilities&SERVICE=WMS I get the capabilities no problem. I am probably being stupid and putting in the wrong URL or something.

Thanks

Chris
Coordinator
Jan 6, 2014 at 4:22 PM
I think the url needs to be the capabilities url.
Jan 6, 2014 at 8:23 PM
Finally got a working WMS on MVC4. I had to create a proxy in the end to allow it to request the capability in order to add to the WMSLayer.
        WebProxy proxyObject = new WebProxy("http://localhost:65105/wms/index",false,null,CredentialCache.DefaultCredentials);

        SharpMap.Layers.WmsLayer WMSlayer = new SharpMap.Layers.WmsLayer("WMSOS250", "http://localhost:65105/wms/index", System.TimeSpan.Parse("500"),proxyObject,CredentialCache.DefaultCredentials);
        WMSlayer.AddLayer("OS250");
        WMSlayer.SRID = 27700;

        WMSlayer.SetImageFormat("image/png");
        WMSlayer.ContinueOnError = true;
        WMSlayer.TimeOut = 5000;
Couple of other little teething problems but open layers can see the layers and pulls the tiles as planned. Will clean up the code and see where it goes.

Thanks for all the help.

Chris