Select to view content in your preferred language

WmsLayer Trouble

1616
9
09-14-2011 06:46 AM
BenTreptow1
Deactivated User
I'm having trouble bringing a WMS layer into my app. I have verified that the server where the WMS service is hosted has a clientaccessploicy.xml, as well as a crossdomain.xml. However, I continue to recieve the following error on WmsLayer.Initialized:

WmsLayer.InitializationFailure = "A security exception occurred while trying to connect to the 'WMS' service. Make sure you have a cross domain policy file available at the root for your server that allows for requests from this application. If not, use a proxy page (handler) to broker communication."

Any ideas? The service is valid too, I can see it in ArcCatalog...

clientaccesspolicy.xml (http://geoint.lmic.state.mn.us/clientaccesspolicy.xml)
crossdomain.xml (http://geoint.lmic.state.mn.us/crossdomain.xml)

void SetBaseLayerWMS()
        {
            try
            {
                BaseLayerWMS = new WmsLayer();
                BaseLayerWMS.ID = "BaseLayerWMS";
                BaseLayerWMS.Layers = new string[] { "met10" };
                BaseLayerWMS.Url = "http://geoint.lmic.state.mn.us/cgi-bin/wmsll?";
                //THIS IS WHAT I'M TRYING TO GET.
                //BaseLayerWMS.Url = "http://geoint.lmic.state.mn.us/cgi-bin/wmsll?VERSION=1.3.0&REQUEST=GetMap&CRS=EPSG:4326&BBOX=44.43,-94.08,45.44,-92.68&WIDTH=847&HEIGHT=611&LAYERS=met10&STYLES=&EXCEPTIONS=XML&FORMAT=image/jpeg&BGCOLOR=0xFEFFFF&TRANSPARENT=TRUE";
                BaseLayerWMS.Initialized += new EventHandler<EventArgs>(BaseLayerWMS_Initialized);
                BaseLayerWMS.InitializationFailed += new EventHandler<EventArgs>(BaseLayerWMS_InitializationFailed);
            }

            catch (Exception)
            {
                throw;
            }
        }
0 Kudos
9 Replies
JenniferNery
Esri Regular Contributor
You can look at the following FAQ page: http://help.arcgis.com/en/webapi/silverlight/help/index.html#//016600000009000000.htm. I tried the Url and found the same exception when placed in Silverlight app, you might want to use the clientaccesspolicy sample from this page. I tried to open it using ArcMap and I am able to see the layers fine.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
The clientaccesspolicy file of your server (http://geoint.lmic.state.mn.us/clientaccesspolicy.xml) restricts the access to some domains.
Is your application hosted by one of these domains?
0 Kudos
BenTreptow1
Deactivated User
My application is hosted on one of these domains. I think their clientaccesspolicy.xml is ok in this case.

I ran my application through Fiddler and noticed that no request is even being made to the remote server. I did this same process again with a wms service I know works and the request was made and everything worked fine. This makes me think that this issue is happening because the WmsLayer class and the url I'm trying to hit, aren't playing nice. I think this because the url (http://geoint.lmic.state.mn.us/cgi-bin/wmsll?) doesn't return anything. It gives me a 400-Bad Request error.

Does this seem like a logical explanation? Again, I know that the wms service works because I can access it in ArcCatalog.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
With Fiddler, you should first see a request to the ClientAccessPolicy file(http://geoint.lmic.state.mn.us/clientaccesspolicy.xml)

Then you should see a request to http://geoint.lmic.state.mn.us/cgi-bin/wmsll?&service=WMS&request=GetCapabilities&version=1.3.0

If if don't see this request, it's probably because you are not authorized to access to the wms service (check the cleintaccesspolicy file). But anyway you should never see a direct request without parameters to http://geoint.lmic.state.mn.us/cgi-bin/wmsll? . It's normal that such request doen't return anything.
0 Kudos
BenTreptow1
Deactivated User
There seems to be some compounding issues here. The first problem was with the clientaccesspolicy.xml and the Visual Studio. Even though the correct domains were listed in the clientaccesspolicy.xml I was never getting through because the request was coming from http://localhost:xxxx which was not included in the clientaccesspolicy.xml on the remote server. The application is in development and not being hosted outside of the Visual Studio web server.

I resolved that issue and it is returning the getcapabilities request. However, the WmsLayer class is not generating the correct url for the getmap request  for some reason. I'm stepping through the class now to see if I can isolate were this breaking. Basically it's building a url that is asking for the wrong FORMAT and CRS for the Layer that I specified.

Here's the url that is being generated by the WmsLayer class:

http://geoint.lmic.state.mn.us/cgi-bin/wmsll?&SERVICE=WMS&REQUEST=GetMap&WIDTH=1258&HEIGHT=879&FORMA...

It should be asking for something like this:

http://geoint.lmic.state.mn.us/cgi-bin/wmsll?&SERVICE=WMS&REQUEST=GetMap&WIDTH=1258&HEIGHT=879&FORMA...

Even though this path does not throw a 400 error, it doesn't return any imagery.

Here's the gecapabilities url too:

http://geoint.lmic.state.mn.us/cgi-bin/wmsll?&service=WMS&request=GetCapabilities&version=1.3.0
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Basically it's building a url that is asking for the wrong FORMAT and CRS for the Layer that I specified.


There is a bug in the current version of the wms layer. The format 'image/jpeg' is not accepted (but 'image/jpg' is OK).
This bug has been fixed for the next releases but for the moment I don't see any workaround except grab the source from codeplex, change the wms file to accept 'image/jpeg' and include it in your project.
Sorry for the trouble.
0 Kudos
BenTreptow1
Deactivated User
Thanks for the info. I noticed that bug when I was stepping through the code. I'll make that change and see if it solves the issue.

Thanks.
0 Kudos
BenTreptow1
Deactivated User
I've been digging through WmsLayer class and I discovered that the reason my wms service is failing is because the WmsLayer class is sending the wrong coordinates for the bounding box in the request.

I know this is happening in the ParseCapabilities method of the WmsLayer class where it's setting the full extent of the layers. It's using the bounding box tag of my layer that I want to use. It looks like it should be using the EX_GeographicBoundingBox tag instead. Is this another bug or is there something wrong with the wms service I'm trying to use? Any suggestions?

Thanks!

This is what the WmsLayer class is generating and doesn't work because it has the wrong spatial reference and extent:

http://geoint.lmic.state.mn.us/cgi-bin/wmsll?&SERVICE=WMS&REQUEST=GetMap&WIDTH=847&HEIGHT=611&FORMAT...

This is what it should be building, this works:

http://geoint.lmic.state.mn.us/cgi-bin/wmsll?&SERVICE=WMS&REQUEST=GetMap&WIDTH=847&HEIGHT=611&FORMAT...

From the get capabilities request for the layer I'm trying to use:

- <Layer queryable="0" opaque="1">
  <Name>met10</Name> 
  <Title>2010 color</Title> 
  <CRS>EPSG:26915</CRS> 
  <CRS>EPSG:4326</CRS> 
  <CRS>EPSG:26914</CRS> 
- <EX_GeographicBoundingBox>
  <westBoundLongitude>-94.08</westBoundLongitude> 
  <eastBoundLongitude>-92.68</eastBoundLongitude> 
  <southBoundLatitude>44.43</southBoundLatitude> 
  <northBoundLatitude>45.44</northBoundLatitude> 
  </EX_GeographicBoundingBox>
  <BoundingBox CRS="EPSG:26915" minx="415485" miny="4920156.9" maxx="525110.1" maxy="5032056.3" resx="0.3" resy="0.3" /> 
- <MetadataURL type="FGDC">
  <Format>text/html</Format> 
  <OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.mngeo.state.mn.us/chouse/airphoto/ecmn10.html" /> 
  </MetadataURL>
  <MaxScaleDenominator>75000000</MaxScaleDenominator> 
  </Layer>
0 Kudos
DominiqueBroux
Esri Frequent Contributor

This is what the WmsLayer class is generating and doesn't work because it has the wrong spatial reference and extent
http://geoint.lmic.state.mn.us/cgi-b...034,5392901.75


The Spatial reference used is the spatial reference of your map. So I guess your map is using SR26915.
The WMS service has to support this spatial reference.
It turns out that your WMS layer does support SR 26915, so it's OK.
It looks like the issue is with the extent. That works if you zoom to the right location:

http://geoint.lmic.state.mn.us/cgi-bin/wmsll?&SERVICE=WMS&REQUEST=GetMap&WIDTH=847&HEIGHT=611&FORMAT...

Sidenote : The full extent is always in geographical coordinates. A wms service can support many SR but the full extent is always returned in geographical coordinates (we could imagine to extent the wms class to return the extent in another SR when it's known)
0 Kudos