I have been working with WMS layers recently and have successfully displayed WMS layers from a variety of services available on the web. There is one service that I have had no luck with at all. Here is the code:
winformsMap1.MapUnit = GeographyUnit.DecimalDegree winformsMap1.BackgroundOverlay.BackgroundBrush = New GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean) Dim wmsImageLayer As WmsRasterLayer wmsImageLayer = New WmsRasterLayer(New Uri("geostor.arkansas.gov/ArcGIS/services/ORTHO2006-WMS/MapServer/WMSServer")) wmsImageLayer.UpperThreshold = Double.MaxValue wmsImageLayer.LowerThreshold = 0 wmsImageLayer.Open() For Each layerName As String In wmsImageLayer.GetServerLayerNames() wmsImageLayer.ActiveLayerNames.Add(layerName) Next
Dim staticOverlay As New LayerOverlay() staticOverlay.Layers.Add("wmsImageLayerArk", wmsImageLayer) winformsMap1.Overlays.Add(staticOverlay) winformsMap1.CurrentExtent = wmsImageLayer.GetBoundingBox wmsImageLayer.Close()
winformsMap1.Refresh()
I have successfully displayed this service in our current application (not ThinkGeo) so I know the service is working.
After applying your code sample to a test project, I noticed that there might be a step missing before sending refreshing map control. Maybe you can have a try to call the GetServerStyleNames method of WmsRasterLayer, and add all the Styles to the ActiveSytleNames collection. For WMS Server, the GetMap request should contain a one-to-one correspondence of Layer and Style parameter, so, if the count of Styles in ActiveStyleNames isn’t equal to the count of Layers in ActiveLayerNames, it will cause a server side error so that the image won’t be send back. However, as WMS Services can be of small differences in specification implementation, if it’s not the problem in your case, could you please grant us access to your Wms Server so that we can get some debugging information? By the way, for now, WmsRasterLayer supports only one style for each Layer, and if the Styles defined on the WMS Server have the same name, it’s not compatible with WmsRasterLayer either. We’ll enhance the Style supporting of WmsRasterLayer in future release. Any further information is appreciated. Thanks. James
I tried your suggestion and added a style for the layer on the service (this particular service only has one layer). It didn't make any difference.
In my previous development work I wrote an application to get images from WMS servers by manually generating the requests and I know that it is not a requrement to request any specific styles, although the 'STYLES' element is supposed to be present in the request. This service is the only one I have tried to connect to (with MS Desktop) that uses WMS service version 1.3.0. I suspect that may have something to do with my problem.
Plesase note that the service I am trying to connect to (geostor.arkansas.gov/ArcGIS/services/ORTHO2006-WMS/MapServer/WMSServer) does not belong to us. It is also not that important that we be able to connect to it. I was just tying to figure out why I couldn't get it to display an image even though it works fine in my previous application. It is a publicly avalable service so you should have no trouble accessing it if you want to have a try.
Hi, Steve Sorry for the late response. I’ve tried several times to connect to the WMS Server address in your application but failed. Since you’ve mentioned the WMS Server is of version 1.3.0, I think maybe this is where the problem lies. It’s proved that WMS Version 1.3.0 is not compatible with WMS Version 1.1.1 or earlier versions, and WmsRasterLayer is implemented against Version 1.1.1. So we may have a problem in handling requests and responses of Version 1.3.0. You can have a look at the request string generated in WmsRasterLayer by calling the method GetRequestUrl and use the Url IE, to see if it works. Here’s another suggestion, since you can generate the request string manually, perhaps you can change the request url of WmsOverlay by handling the SendingRequest event of WmsRasterSource. Below is a code segment in purpose of doing this. WmsRasterSource source = wmsImageLayer.ImageSource as WmsRasterSource; source.SendingRequest += new EventHandler<SendingRequestWmsRasterSourceEventArgs>(source_SendingRequest);
Thanks very much for your help, it allowed me to create a workaround for now. I'm not sure how reliable it will be in the long run. I'd like to see ThinkGeo support version 1.3.0.
In order to make this service work I had to change three things in the request string:
VERSION=1.3.0 to VERSION=1.1.1
CRS=EPSG:4326 to SRS=EPSG:4326
For some reason output format is case sensitive in the server so IMAGE/PNG goes to image/png.
Here's the code:
Private Sub oWMSRasterSource_SendingRequest(ByVal sender As Object, ByVal e As SendingRequestWmsRasterSourceEventArgs) Dim sRequeststring = e.RequestUri.OriginalString Dim sOutputFormat As String = CType(sender, WmsRasterSource).OutputFormat
If sRequeststring.ToUpper.Contains("VERSION=1.3.0") Then '***** This is a version 1.3.0 service, not compatible with ThinkGeo so adjust the string sRequeststring = sRequeststring.ToUpper.Replace("&VERSION=1.3.0", "&VERSION=1.1.1") sRequeststring = sRequeststring.ToUpper.Replace("&CRS=", "&SRS=") sRequeststring = sRequeststring.ToUpper.Replace(sOutputFormat, sOutputFormat.ToLower) e.RequestUri = New Uri(sRequeststring) End If Debug.WriteLine(e.RequestUri.OriginalString)
I remembered that the version 1.3.0 is still not very stable when we developed the WmsRasterSource, we will review this change to see if there is a better way to support both of them in recent future.
After upgrading to the latest version of Desktop (5.5) I noticed that the RequestUri property of SendingRequestWmsRasterSourceEventArgs is now obsolete and is being replaced with a WebRequest class. I was using the workaround above to enable compatibility with WMS servers using the 1.3.0 protocol. To maintain my workaround I need to be able to do the following:
Public Shared Sub oWMSRasterSource_SendingRequest(ByVal sender As Object, ByVal e As ThinkGeo.MapSuite.Core.SendingRequestWmsRasterSourceEventArgs) Dim sRequeststring = e.WebRequest.RequestUri.OriginalString Dim sOutputFormat As String = CType(sender, WmsRasterSource).OutputFormat
If sRequeststring.ToUpper.Contains("VERSION=1.3.0") Then '***** This is a version 1.3.0 service, not compatible with Think Geo so adjust the string sRequeststring = sRequeststring.ToUpper.Replace("&VERSION=1.3.0", "&VERSION=1.1.1") sRequeststring = sRequeststring.ToUpper.Replace("&CRS=", "&SRS=") sRequeststring = sRequeststring.ToUpper.Replace(sOutputFormat, sOutputFormat.ToLower) e.WebRequest.RequestUri = New Uri(sRequeststring) End If End Sub
However this will not work because the RequestURI property is read only.
Thanks for your post, now, now WebRequest.RequestUri have changed only have get method, but it allow you to create the WebRequest by your self.
So you can create a new WebRequest then assign to e.WebRequest. Dim webRequest__1 As WebRequest = WebRequest.Create(sRequeststring) e.WebRequest = webRequest__1