WMS Server call in .net

Piero Cavalieri piero.cavalieri at GMAIL.COM
Tue May 9 00:58:58 PDT 2006


rock well ha scritto:

Hi all i was wondering if there is an equivalent script for wms request for
asp script with iis in the below link

http://ms.gis.umn.edu/docs/howto/wms_server,
i am trying to do the same thing in vb.net ....

Any suggestions please .....


I do:

public Map  getMap(string queryString)
        {
            string mapImgUrl = null;
            string mapwidth  = null;
            string mapheight = null;
            string scalebar = null;
            string imgxy = null; //[center] of the image
            string imgext = null;
            string legend = null;
            string referenceMap = null;

            Map map = null; //holds all map value


            try {

                HttpWebRequest webRequest = (HttpWebRequest)
WebRequest.Create(queryString);

                webRequest.Timeout=10000;
                webRequest.Method = "GET";
                // Send the WebRequest and read response
                HttpWebResponse webResponse = (HttpWebResponse)
webRequest.GetResponse();
                Stream sResponse = webResponse.GetResponseStream();
                StreamReader reader = new StreamReader(sResponse);

                //first line is additional info from MapServer
                string header = reader.ReadLine();

                if(header == "<HTML>") { //error
                    string message = reader.ReadToEnd();
                    message += "\n\n\"" + header + message + "\"\n\n";
                    throw new Exception(message);
                }

                //actual parameters
                XmlDocument xmldoc = new XmlDocument();
                string doc = reader.ReadToEnd();
                xmldoc.LoadXml(doc);
                xmldoc.PreserveWhitespace = true;
                XmlNode root = xmldoc.DocumentElement;

                mapImgUrl = root.SelectSingleNode
("img").Attributes["value"].Value;
                mapwidth = root.SelectSingleNode
("mapwidth").Attributes["value"].Value;
                mapheight = root.SelectSingleNode
("mapheight").Attributes["value"].Value;
                scalebar = root.SelectSingleNode
("scalebar").Attributes["value"].Value;
                imgxy = root.SelectSingleNode
("imgxy").Attributes["value"].Value;
                imgext = root.SelectSingleNode
("imgext").Attributes["value"].Value;
                referenceMap = root.SelectSingleNode
("referenceMap").Attributes["value"].Value;
                legend = root.SelectSingleNode("legend").InnerText;

                sResponse.Close();
                reader.Close();
                webResponse.Close();

                map = new Map(mapImgUrl, mapwidth, mapheight, scalebar,
imgxy, imgext, legend, referenceMap);

                sResponse.Close();
                reader.Close();
                webResponse.Close();

            } catch (Exception ex) {
                throw new
Exception("queryString:"+queryString+"\n"+ex.StackTrace);
            }

            return map;

        } //method

web_template.xml:

<?xml version="1.0" encoding="utf-8" ?>
<map>
 <img value="[img]"/>
 <mapwidth value="[mapwidth]"/>
 <mapheight value="[mapheight]"/>
 <scalebar value="[scalebar]"/>
 <referenceMap value="[ref]"/>
 <imgxy value="[center]"/>
 <imgext value="[mapext]"/>
 <legend>
     <![CDATA[
     [legend]
     ]]>
 </legend>
</map>



[Serializable]
    public class Map
    {

        public string mapImgUrl = "";
        public string mapwidth = "";
        public string mapheight = "";
        public string scalebar = "";
        public string imgxy = "";
        public string imgext = "";
        public string legend = "";
        public string referenceMap = "";

        public Map(string mapImgUrl, string mapwidth, string mapheight,
string scalebar, string imgxy, string imgext, string legend, string
referenceMap)
        {
            this.mapImgUrl = mapImgUrl;
            this.mapwidth = mapwidth;
            this.mapheight = mapheight;
            this.scalebar = scalebar;
            this.imgxy = imgxy;
            this.imgext = imgext;
            this.legend = legend;
            this.referenceMap = referenceMap;
        }
    }

How u do the call depends if u use postbacks or ajax. If ajax, wrap the
method with ajax serverside call, and then do javascript  call to that
method (this depends on ajax library used, I used AjaxPro).
If postbacks, u do the work in PageLoad. Take posted parameters from user
interface, build the url, call the method above (or similar...), then u can
use returned values (image url, extension ecc.) in the Page with classic asp
style: <image src="<%= mapUrl%>" /> ecc.

Ciao
   Piero
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20060509/27b2cb76/attachment.htm>


More information about the MapServer-users mailing list