Hi,
I am trying to connect to a WMS feed:
geostore.com/OGC/OGCInterface?SERVICE=WMS&UID=xxxxxx&PASSWORD=xxxxxx&INTERFACE=ENVIRONMENT&LC=200000000000000000000000000000000000000000000000000000000000000000000000000
but get the following error:
‘ows’ is an undeclared prefix. Line 131, position 10.
I am using desktop edition build “Daily Full Production 8.0.0.236”. The line that crashes is simply the open statement.
WmsRasterLayer wms = new WmsRasterLayer(new Uri(utxtUrl.Text));
wms.Open();
And the full exception is:
System.Xml.XmlException was caught
HResult=-2146232000
Message=‘ows’ is an undeclared prefix. Line 131, position 10.
Source=System.Xml
LineNumber=131
LinePosition=10
SourceUri=geostore.com/OGC/OGCInterface?SERVICE=WMS&UID=xxxxxx&PASSWORD=xxxxxx&INTERFACE=ENVIRONMENT&LC=200000000000000000000000000000000000000000000000000000000000000000000000000&REQUEST=GetCapabilities
StackTrace:
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.Throw(String res, String arg, Int32 lineNo, Int32 linePos)
at System.Xml.XmlTextReaderImpl.LookupNamespace(NodeData node)
at System.Xml.XmlTextReaderImpl.ElementNamespaceLookup()
at System.Xml.XmlTextReaderImpl.ParseElement()
at System.Xml.XmlTextReaderImpl.ParseElementContent()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlLoader.LoadNode(Boolean skipOverWhitespace)
at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc)
at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
at System.Xml.XmlDocument.Load(XmlReader reader)
at ThinkGeo.MapSuite.Core.WmsRasterSource.D00=(String 2lM=, WebProxy 21M=, ICredentials 3FM=)
at ThinkGeo.MapSuite.Core.WmsRasterSource.DU0=(String 1FM=)
at ThinkGeo.MapSuite.Core.WmsRasterSource.OpenCore()
at ThinkGeo.MapSuite.Core.RasterSource.Open()
at ThinkGeo.MapSuite.Core.RasterLayer.OpenCore()
at ThinkGeo.MapSuite.Core.Layer.Open()
at enzo.PopupForms.WMSPopupForm.GetAvailableLayers() in c:\Users\Jonathan\Source\Workspaces\Pear Technology\Enzo\enzo\PopupForms\WMSPopupForm.cs:line 54
InnerException:
Hope you can help me with this one.
Regards,
Jonathan
'ows' is an undeclared prefix. Line 131, position 10
Hi Jonathan,
It looks the capability XML is invalid, you can download it: geostore.com/OGC/OGCInterface?SERVICE=WMS&UID=[YOURUID]&PASSWORD=[YOURPASSWORD]&INTERFACE=ENVIRONMENT&LC=200000000000000000000000000000000000000000000000000000000000000000000000000&REQUEST=GetCapabilities
And open the file you will find the XML haven’t declared the “ows” namespace but it used it: <ows:extendedcapabilities>
So please let WMS provider modify this.
Regards,
Don</ows:extendedcapabilities>
Don,
Thanks, I have emailed the WMS provider (the UK Government’s Environment Agency) and will let you know how they respond. I did have a look at the XML and can see that the namespace is not declared - as you pointed out, although I understand from a colleague that it does work with Quantum GIS (QGIS), so possibly they are less strict in some way?
Regards,
Jonathan
Hi Jonathan,
Thanks for let us know that, any further problem please let us know.
I am not sure why QGIS haven’t thrown exception, I think maybe that’s because they choose different strategy for validation or handle exception.
Regards,
Don
Hi,
A similar problem seems to have started again with the same WMS feeds from this provider, although the returned error is different. This is the exception I am getting:
System.Net.WebException was caught
HResult=-2146233079
Message=The remote server returned an error: (401) Unauthorized.
Source=System
StackTrace:
at System.Net.HttpWebRequest.GetResponse()
at ThinkGeo.MapSuite.Core.WmsRasterSource.SendWebRequestCore(WebRequest webRequest)
at ThinkGeo.MapSuite.Core.WmsRasterSource.SendWebRequest(WebRequest webRequest)
at ThinkGeo.MapSuite.Core.WmsRasterSource.GetImageCore(RectangleShape worldExtent, Int32 canvasWidth, Int32 canvasHeight)
at ThinkGeo.MapSuite.Core.RasterSource.GetImage(RectangleShape worldExtent, Int32 canvasWidth, Int32 canvasHeight)
at ThinkGeo.MapSuite.Core.RasterLayer.DrawCore(GeoCanvas canvas, Collection`1 labelsInAllLayers)
at ThinkGeo.MapSuite.Core.Layer.Draw(GeoCanvas canvas, Collection`1 labelsInAllLayers)
at ThinkGeo.MapSuite.DesktopEdition.LayerOverlay.DrawCore(GeoCanvas canvas)
at ThinkGeo.MapSuite.DesktopEdition.Overlay.sRM=(GeoCanvas canvas)
at ThinkGeo.MapSuite.DesktopEdition.Overlay.Draw(GeoCanvas canvas)
at ThinkGeo.MapSuite.DesktopEdition.WinformsMap.dhQ=(IEnumerable`1 drawingOverlays, RectangleShape extent)
at ThinkGeo.MapSuite.DesktopEdition.WinformsMap.dRQ=(RectangleShape drawingExtent, RectangleShape extent)
at ThinkGeo.MapSuite.DesktopEdition.WinformsMap.lRQ=(RectangleShape extent)
at ThinkGeo.MapSuite.DesktopEdition.WinformsMap.kxQ=(Int32 delayInterval, RectangleShape extent)
at ThinkGeo.MapSuite.DesktopEdition.WinformsMap.Refresh()
at enzo.MapEditing.cMapNavigation.RefreshMap() in c:\Users\User\Source\Workspaces\Pear Technology\Enzo\enzo\MapEdit\MapNavigation.cs:line 71
InnerException:
.
I have tried using the MapSuite GIS Editor and get a black box where I would expect the data to be, however QGIS seems OK I think.
Do you have any thoughts about why I might be getting this error?
Regards,
Jonathan
Hi Jonathan,
Just as the exception message showing up that seems like the credentials you provided is not correct, you see here as following is the message returned:
The remote server returned an error: (401) Unauthorized
Thanks,
Johnny
Johnny,
Thanks. I thought this message might have got lost tacked on to the end of an old thread so I re-raised it as a new question and added some more detail, including the URL that (according to the provider) only optionally needs a UID and PASSWORD. Unfortunately nothing they suggested and I tried worked, so what sort of additional authorization might be expected from a WMS feed?
Regards,
Jonathan
Hi Jonathan,
It looks you still hadn’t comment your userName and passWord, please modify them in your post for security.
Today I tested your information again, it looks the request url should works like this, please replace the uid and password in it.
geostore.com/OGC/OGCInterface?BBOX=-5.625,56.25,0,61.875&EXCEPTIONS=application/vnd.ogc.se_inimage&FORMAT=IMAGE/PNG&HEIGHT=256&layers=ENVIRONMENT&PASSWORD=[YourPassword]&REQUEST=GetMap&SERVICE=WMS&SRS=EPSG:4326&styles=DEFAULT&UID=[YourUID]&VERSION=1.1.1&WIDTH=256
As below is my test code:
private void WpfMap_Loaded(object sender, RoutedEventArgs e)
{
Map1.MapUnit = GeographyUnit.DecimalDegree;
WmsOverlay wms = new WmsOverlay(new Uri(“geostore.com/OGC/OGCInterface”));
wms.Parameters.Add(“UID”, “YOURUID”);
wms.Parameters.Add(“PASSWORD”, “YOURPASSWORD”);
wms.Parameters.Add(“layers”, “ENVIRONMENT”);
wms.Parameters.Add(“styles”, “DEFAULT”);
wms.SendingWebRequest += wms_SendingWebRequest;
Map1.Overlays.Add(wms);
Map1.CurrentExtent = new RectangleShape(-9.49714, 61.581, 4.56425, 49.7668);
Map1.Refresh();
}
void wms_SendingWebRequest(object sender, SendingWebRequestEventArgs e)
{
Debug.WriteLine(e.WebRequest.RequestUri);
}
BTW, it looks their server is not stable, when I refresh the same url I tested and get a image before, I get an exception now.
So I think your code won’t works correct for it.
Regards,
Don
Don,
Thanks for the information. I have changed the original message to remove the UID and PWD, also I have tried your suggestions and I have reached a working point although not quite the way you suggested.
Firstly I don’t appear to have WmsOverlay as an available type but I have used WmsRasterLayer and maybe that will explain the differences?
My code currently needs some work but the chopped about version looks like this:
01.
/// <summary>
02.
/// Add a WMS raster layer
03.
/// </summary>
04.
/// <param name=“wmsData”></param>
05.
private
void
AddWMSLayer(WmsDataSource wmsData, LayerOrderRecord layerRecord)
06.
{
07.
// Adding Wms Layer
08.
//WmsRasterLayer wms = new WmsRasterLayer(new Uri(wmsData.path));
09.
WmsRasterLayer wms =
new
WmsRasterLayer(
10.
new
Uri(
"<a href="geostore.com/OGC/OGCInterface?SERVICE=WMS&UID=UDATAGOV2011&PASSWORD=datagov2011&FORMAT=image/png&INTERFACE=ENVIRONMENT&EXCEPTIONS=INIMAGE">geostore.com/OGC/OGCInte...NS=INIMAGE</a>"
));
11.
12.
wms.IsTransparent =
true
;
13.
//wms.OutputFormat = “image/png”;
14.
wms.Crs =
“EPSG:27700”
;
15.
16.
wms.Parameters.Add(
“FORMAT”
,
“image/png”
);
17.
18.
wms.Parameters.Add(
“UID”
,
“xxxxxx”
);
19.
wms.Parameters.Add(
“PASSWORD”
,
“xxxxxx”
);
20.
wms.Parameters.Add(
“EXCEPTIONS”
,
“INIMAGE”
);
21.
//wms.Parameters.Add(“EXCEPTIONS”, “application/vnd.ogc.se_inimage”);
22.
//wms.Parameters.Add(“LAYERS”, “ENVIRONMENT”);
23.
//wms.Parameters.Add(“LC”, “0”);
24.
wms.Parameters.Add(
“STYLES”
,
“Default”
);
25.
26.
wms.SendingWebRequest += wms_SendingWebRequest;
27.
28.
29.
foreach
(String layerName
in
wmsData.layers) { wms.ActiveLayerNames.Add(layerName); }
30.
wms.Name = wmsData.name;
31.
32.
// Set state information (wms data source and layer name the same)
33.
wms.IsVisible = ProjectHelper.IsLayerVisible(wmsData.name, wmsData.name);
34.
35.
// Only add layer if WMS works (otherwise get overloaded with errors)
36.
try
37.
{
At the moment there is a certain amount of overlap between the URI and the parameters.add(…) statements that needs a tidy. Oddly some appear to be needed in both places, also using EXCEPTIONS=INIMAGE appeared to be essential otherwise it came back with an invalid value for exceptions response (surprisingly EXCEPTIONS= application/vnd.ogc.se_inimage did not work).
Thanks,
Jonathan
Hi Jonathan,
If that can work for you, I think choose which class is not important. I tested your WMS server but it looks cannot be accessed today.
So I think if you solved the parameter problem, sometimes it maybe still will get error tile because server stable problem.
Regards,
Don
Don,
Thanks again form the help, the server seems to be working OK at the moment and I have now reworked my code to be much neater and work nicer. The key bits for me were (a) using parameters for UID and PASSWORD otherwise they seem to get lost somewhere if included in the WmsRasterLayer’s URI and (b) having the exceptions parameter with a value of INIMAGE (neither the full version or omitting it entirely seemed to work).
Regards,
Jonathan
Hi Jonathan,
I am glad to hear that works for you.
Regards,
Don