Apparently it doesn’t seem to be working as expected- even if the WMS layer is stored in an MXD document. Instead of returning the layer attributes, it returns the WMS GetFeatureInfo request i.e. something similar to:
http://www2.demis.nl/WMS/wms.ashx?WMS=SAMPLE&VERSION=1.3.0&REQUEST=GetFeatureInfo&< >CRS=CRS:84&BBOX=-180,-90,180,90&WIDTH=1304&HEIGHT=652&LAYERS=Countries& QUERY_LAYERS=Countries& STYLES=&EXCEPTIONS=XML&FORMAT=image/png&INFO_FORMAT=text/html&FEATURE_COUNT=50&I=304&J=192
The workaround is to use this URL to make a direct call to the WMS service and then return the results with an asynchronous request. And since the Identify task is an asynchronous request itself, you have to get one asynchronous request to call another asynchronous request. Clear as mud – right?
This example is based on the Identify Task Silverlight sample so I will assume you have the ‘standard’ identify functionality working.
The ‘first thing you need to do is create a new WCF Service which would be the one that will make the WMS GetFeatureInfo request. Lets imaginatively call it ‘WMSService’. Its Service Contract would be:
And the WMSService.svc.cs file would look like:
Next we need to get back to our Silverlight project and add a reference to the new WCF Service:
Then, replace the cb_SelectionChanged event – remember I am assuming you are using the original Identify sample- with the following:
Notice that before I send the FeatureInfo request on its merry way, I am changing the requested format from html to xml which would be easier handled in Silverlight, rather than an HTML snippet.
So when the request completes, it will hit the GetFeatureInfoCompleted event. The response will get returned as an XML string, and the problem now is how to display this in the Identify grid since we don’t know anything about the number or type of attributes that will get returned.
The magic here occurs via the GenerateData and ToDataSource functions. Both of them have been taken from this excellent blog post by Vladimir Bodurov: How to Bind Silverlight DataGrid From IEnumerable of IDictionary by Transforming Each Dictionary Key Into a Property of Anonymous Typed Object. I changed the GenerateData function to recursively loop through the returned XML as follows:
You can download the DataSourceCreator.cs here.
Once finished you should be able to use the Identify tool on any WMS layer and get back the results. Well, ‘any’ may be an overstatement as I only tried it with a couple!