Hello,
I have issue with calling GeoServer map service using WmsRasterLayer. I made call perfectly passing every parameters to get response from Geo server and I got response from there but still it does not show map.
I am attaching my code with the post.
Also I tried to render my created layer on geoserver I got error like
Unexpected XML declaration. The XML declaration must be the first node in the document, and no white space characters are allowed to appear before it. Line 4582, position 14.
Please check the code and help me in this.
Thank you.
GeoServer_RequestMethod.txt (4.86 KB)
Issue with WmsRasterLayer while calling Geoserver map service
Hi Eric,
Sorry I haven’t get time to create a GeoSever today. I will try to create one and test your code.
For now, could you please do some try like this:
WmsRasterLayer layer = new WmsRasterLayer();
layer.SendingWebRequest += new EventHandler<SendingWebRequestEventArgs>(layer_SendingWebRequest);
void layer_SendingWebRequest(object sender, SendingWebRequestEventArgs e)
{
Uri uri = e.WebRequest.RequestUri;
}
Here you can get the request uri and you can try that in browser, so we can find which parameter incorrect.
Another way for view that is when you show map, right click on tile, copy the link and directly render it in browser.
Please let me know if you find anything.
Regards,
Don
Hello Done,
Thank you for your reply.
But I check the Uri with Fiddler when I make request to Geoserver and when I copy paste that URL of request in my browser than it loads map correctly.
I don’t know why it not loads in RasterLayer.
And as per your code I tried that also and I got result like
AbsoluteUri = 192.168.1.149:8080/geoserver/topp/wms?SERVICE=WMS&REQUEST=GetCapabilities&
I don’t know why it puts REQUEST=GetCapabilities as in my Uri that would be like REQUEST=GetMap.
Can you please check all with Fiddler that is that some thing that I miss.
Thank you for your reply.
Eric.
Hello Don,
One more thing that I have tried to paste request url in browser and I got response like what I am attaching with the post.
Request url is : 192.168.1.149:8080/geoserver/topp/wms?SERVICE=WMS&REQUEST=GetCapabilities
It returns me the XML file with details of geoserver.
Please check the file.
Thank you.
Eric.
getcapabilities_1.3.0.xml (152 KB)
Hi Eric,
For WMS request, I think we should get capabilities before get map, that’s the correct steps.
You said: “when I copy paste that URL of request in my browser than it loads map correctly”, does that work for GetCapabilities or GetMap?
If that works for GetMap, could you please paste the uri for tile request, we can help you check whether the request link miss anything.
Regards,
Don
Hello Don,
Thank you for your reply.
Yes I get map load in browser with GetMap.
Here I am pasting URL that I paste in Browser to load map.
192.168.1.149:8080/geoserver/topp/ows?SERVICE=WMS&REQUEST=GetMap&WIDTH=1100&HEIGHT=821&LAYERS=topp:states&FORMAT=application/openlayers&SRS=EPSG:4326&BBOX=-124.73142200000001,24.955967,-66.969849,49.371735&VERSION=1.1.0&STYLES=&EXCEPTIONS=application/vnd.ogc.se_xml&service=WMS
Thank you.
Eric.
Hi Eric,
If the URI can return correct image, I think the problem should because we haven’t rendered the layer correct.
Your parameters in URL looks OK, but when you hard code the BBOX, the scale should be 36911986.875.
You mentioned an exception is thrown, could you please paste some screenshots about the exception and how the map looks like.
Regards,
Don
Hello Don,
Thank you for your reply.
I did not get map load. Yes I know that Bounding box (Extend) is getting different in WinformsMap object than I get in GeoServer response.
And I am sending my whole application code with the post. Please check the code and let me know if I made some mistake in this.
Please try to check code ASAP as I have to finish this task as early as possible. thank you for your support.
Thank you.
Eric.
SampleDesktopApp.zip (768 KB)
Hi Eric,
Thanks for your project, I will help you to review the code for make sure everything is correct.
In fact we need to reply many tickets and posts, so we don’t have too much time on one topic in one day.
Unlucky I deploy Geoserver is not smooth so I cannot directly debug the code today.
But I have tried to find some public WMS servers created by GeoServer instead of creating the GeoServer local, I think I can reproduce the problem tomorrow if everything goes well.
Please let me know if you get any good news or anything you thought should be helpful.
Regards,
Don
Hi Eric,
Thanks for your comments and detailed samples. As the error states, the first four characters of an xml document should be <?xml. no ifs, ands or buts, spaces etc. the exception should come from the code used for requesting and parsing the WMS capabilities xml file. But it’s weird that everything looks fine if you try the attached “getcapabilities_1.3.0.xml”. I hard-code the Capabilities file you provided in the thread, with our source code, but seems that everything is fine, I can create the tile image request URL successfully, just shown as below:
192.168.1.149:8080/geoserver/topp/ows?SERVICE=WMS&?&BBOX=-124.73142200000001,24.955967,-66.969849,49.371735&EXCEPTIONS=application/vnd.ogc.se_xml&format=image/png&height=821&LAYERS=topp:states&
request=GetMap&SERVICE=WMS&SRS=EPSG:4326&styles=&VERSION=1.1.0&width=1100
You see the URL is correct. Seems like the version of the Capabilies is 1.3.0, but content in getcapabilities_1.3.0.xml shows the version of 1.1.0. Please do a check.
The steps we are using is parsing the capabilities from the server and then get the URL of GetMap from the Capabilities. in other words, before moving forward, we need to make sure where the problem might be. can you try the following options to determine the problem?
1. Try the code as below to make sure the error comes from the Capabilities file itself. If runs into error, I guess we need to check the capabilites from the server, maybe it’s not the one you attached in the thread:
WmsRasterLayer wmsRaster =
new
WmsRasterLayer(
new
Uri(
"<a href=“192.168.1.149”>192.168.1.149</a>:8080/geoserver/topp/wms"
), WebProxy.GetDefaultProxy());
wmsRaster.UpperThreshold =
double
.MaxValue;
wmsRaster.LowerThreshold = 0;
wmsRaster.Crs =
“EPSG:4326”
;
wmsRaster.Parameters.Add(
“service”
,
“WMS”
);
wmsRaster.Parameters.Add(
“version”
,
“1.1.0”
);
wmsRaster.Parameters.Add(
“request”
,
“GetMap”
);
wmsRaster.Parameters.Add(
“layers”
,
“topp:states”
);
wmsRaster.Parameters.Add(
“styles”
,
“”
);
wmsRaster.Parameters.Add(
“bbox”
,
“-124.73142200000001,24.955967,-66.969849,49.371735”
);
wmsRaster.Parameters.Add(
“srs”
,
“EPSG:4326”
);
wmsRaster.Parameters.Add(
“format”
,
“application/openlayers”
);
wmsRaster.Parameters.Add(
“width”
, ktpsMap.Width.ToString());
wmsRaster.Parameters.Add(
“height”
, ktpsMap.Height.ToString());
wmsRaster.Name =
“geoserver”
;
wmsRaster.OutputFormat =
“image/png”
;
wmsRaster.Exceptions =
“application/vnd.ogc.se_xml”
;
wmsRaster.Open();
// We check the capability file here.
2. If everything is ok with first step, please try run the sample you attached. if it runs into exception, I guess we need to take the advantage of event SendingWebRequest to log all the request URLs, and then check if these URLs are ok manually.
Thanks,
Johnny
Hello Johnny,
Thank you for your reply.
I have check that Geo server returns Capabilities XML file on request.
And I got map loaded if I pass
wmsRaster.Parameters.Add(
"format"
,
"image/png"
);
in request parameters. but if I pass
wmsRaster.Parameters.Add(
"format"
,
"text/html; subtype=openlayers"
);
or
wmsRaster.Parameters.Add(
"format"
,
"application/openlayers"
);
It did not load map with raster layer.
is there any other parameter that I have to pass to load map with application/openlayers. As with image/png it only allow me to view that layer. I am not able to panning the map and zooming the map.
And Don, Yes I know that you have to reply so many threads/posts over here but I have to complete task so for that I asked to check it soon.
Thanks for your help Don.
Thank you.
Eric.
Hi Eric,
In wms server edition, the "GetMap"only support the below image format as follows: image/png, image/jpeg, image/gif.
I am not very clear the reason why you want to pass “application/openlayers” format to the server. As I know, return an image is standard defined by OpenGIS. No matter what wms server is, it doesn’t need to care the client actions like zoom, pan, these actions are handled by the client render engine like openlayers etc. Actually, I am wondering why you give a full map size for the request tile?
wmsRaster.Parameters.Add(“width”, ktpsMap.Width.ToString());
wmsRaster.Parameters.Add(“height”, ktpsMap.Height.ToString());
Basically, we would give a 256*256 tile size for each tile. would you please comment out the above codes?
Thanks,
Troy