private void btnTestWFS_Click(object sender, EventArgs e) { try { this.Cursor = Cursors.WaitCursor; string url = txtWFSUrl.Text.Trim(); if (!String.IsNullOrEmpty(txtServiceName.Text.Trim())) { url = WebFunctions.AppendParametersToUrl(url, "ServiceName=" + txtServiceName.Text.Trim()); } string param = "REQUEST=GetCapabilities&VERSION=1.1.1&SERVICE=WFS"; url = WebFunctions.AppendParametersToUrl(url, param); string capabilities = WebFunctions.RemoveDOCTYPE(WebFunctions.DownloadXml(url)); XmlDocument doc = new XmlDocument(); doc.LoadXml(capabilities); xmlViewTree1.XmlDocument = doc; } catch (Exception ex) { this.Cursor = Cursors.Default; MessageBox.Show("ERROR: " + ex.Message); } finally { this.Cursor = Cursors.Default; } }
private void ParseParameters(Parameters Request) { //check for exception format if (Request["EXCEPTIONS"] != null) { if (Request["EXCEPTIONS"] != "application/vnd.ogc.se_inimage" && Request["EXCEPTIONS"] != "application/vnd.ogc.se_blank" && Request["EXCEPTIONS"] != "application/vnd.ogc.se_xml") { WriteError("Invalid exception format " + Request["EXCEPTIONS"] + " must be 'application/vnd.ogc.se_inimage', 'application/vnd.ogc.se_blank' or 'application/vnd.ogc.se_xml'."); } else { switch (Request["EXCEPTIONS"]) { case "application/vnd.ogc.se_inimage": this.Exceptions = WMSExceptionType.se_in_image; break; case "application/vnd.ogc.se_blank": this.Exceptions = WMSExceptionType.se_blank; break; /* SE_XML is already the default value * default: * this.Exceptions = WMSExceptionType.SE_XML; * break; */ } } } if (Request["REQUEST"] == null) { WriteError("mandatory REQUEST parameter is missing"); } if (Request["REQUEST"].ToUpper().IndexOf("MAP") != -1) { this.Request = WMSRequestType.GetMap; } else if (Request["REQUEST"].ToUpper().IndexOf("CAPABILITIES") != -1) { this.Request = WMSRequestType.GetCapabilities; } else if (Request["REQUEST"].ToUpper().IndexOf("FEATUREINFO") != -1) { this.Request = WMSRequestType.GetFeatureInfo; } else if (Request["REQUEST"].ToUpper().IndexOf("DESCRIPETILES") != -1) { this.Request = WMSRequestType.DescriptTiles; } else if (Request["REQUEST"].ToUpper().IndexOf("GETTILE") != -1) { this.Request = WMSRequestType.GetTile; } else if (Request["REQUEST"].ToUpper().IndexOf("GENERATETILES") != -1) { this.Request = WMSRequestType.GenerateTiles; } else { WriteError("REQUEST parameter is either missing, erroneous, or not supported. Supported values are: 'GetMap', 'map', 'GetCapabilities','capabilities'"); } if (Request["VERSION"] == null && Request["WMTVER"] == null) { if (this.Request != WMSRequestType.GetCapabilities) { WriteError("mandatory VERSION parameter is either missing or erronous. Must be: 'WMTVER=1.0.0' or 'VERSION=1.x.x'"); } else { this.Version = "1.1.1";//default version } } else { if (Request["WMTVER"] != null && Request["VERSION"] == null) { this.Version = Request["WMTVER"]; } else if (Request["WMTVER"] == null && Request["VERSION"] != null) { this.Version = Request["VERSION"]; } } #region Nicht Standard (für GenerateTiles Request: WMS2Tiles für Bing Map Controll!!) if (this.Request == WMSRequestType.GenerateTiles) { if (Request["BBOXSRS"] != null) { if (Request["BBOXSRS"].IndexOf("EPSG:") == -1) { WriteError("only EPSG based coordinate systems are supported!", "InvalidBBOXSRS"); } string[] srsid = Request["BBOXSRS"].Split(':'); this.BBoxSRS = int.Parse(srsid[srsid.Length - 1]); } if (Request["ZOOMLEVEL"] != null) { this.ZoomLevel = int.Parse(Request["ZOOMLEVEL"]); } if (Request["REQUESTKEY"] != null) { _requestKey = Request["REQUESTKEY"]; } if (Request["TILEROW"] == null) { WriteError("mandatory TILEROW parameter is missing."); } else { this.TileRow = int.Parse(Request["TILEROW"]); } if (Request["TILECOL"] == null) { WriteError("mandatory TILECOL parameter is missing."); } else { this.TileCol = int.Parse(Request["TILECOL"]); } } #endregion if (this.Request != WMSRequestType.GetCapabilities && this.Request != WMSRequestType.DescriptTiles) { if (Request["SRS"] == null && Request["CRS"] == null) { WriteError("mandatory SRS, CRS parameter is missing."); } else { if (Request["SRS"] != null) { if (Request["SRS"].IndexOf("EPSG:") == -1) { WriteError("only EPSG based coordinate systems are supported!", "InvalidSRS"); } string[] srsid = Request["SRS"].Split(':'); this.SRS = int.Parse(srsid[srsid.Length - 1]); } else if (Request["CRS"] != null) { if (Request["CRS"].IndexOf("EPSG:") == -1) { WriteError("only EPSG based coordinate systems are supported!", "InvalidCRS"); } string[] srsid = Request["CRS"].Split(':'); this.SRS = int.Parse(srsid[srsid.Length - 1]); } } if (this.Request == WMSRequestType.GetMap || this.Request == WMSRequestType.GetTile) { if (Request["FORMAT"] == null) { WriteError("mandatory FORMAT parameter is missing."); } else { switch (Request["FORMAT"].ToLower()) { case "image/gif": this.Format = WMSImageFormat.gif; break; case "image/bmp": this.Format = WMSImageFormat.bmp; break; case "image/jpg": case "image/jpeg": this.Format = WMSImageFormat.jpeg; break; case "image/png": this.Format = WMSImageFormat.png; break; case "gif": this.Format = WMSImageFormat.gif; break; case "png": this.Format = WMSImageFormat.png; break; case "jpg": this.Format = WMSImageFormat.jpeg; break; case "application/vnd.google-earth.kml+xml": this.Format = WMSImageFormat.kml; break; default: WriteError("Format " + Request["FORMAT"] + " is not supported.", "InvalidFormat"); break; } } } if (this.Request == WMSRequestType.GetTile) { if (Request["LAYER"] == null) { WriteError("mandatory LAYER parameter is missing."); } else { this.Layer = Request["LAYER"]; } if (Request["STYLE"] == null) { WriteError("mandatory STYLE parameter is missing."); } else { this.Style = Request["STYLE"]; } if (Request["SCALE"] == null) { WriteError("mandatory SCALE parameter is missing."); } else { this.Scale = double.Parse(Request["SCALE"].Replace(",", "."), _nhi); } if (Request["TILEROW"] == null) { WriteError("mandatory TILEROW parameter is missing."); } else { this.TileRow = int.Parse(Request["TILEROW"]); } if (Request["TILECOL"] == null) { WriteError("mandatory TILECOL parameter is missing."); } else { this.TileCol = int.Parse(Request["TILECOL"]); } } else { if (this.Request == WMSRequestType.GetMap || this.Request == WMSRequestType.GetFeatureInfo) { if (Request["HEIGHT"] == null) { WriteError("mandatory HEIGHT parameter is missing."); } else { this.Height = int.Parse(Request["HEIGHT"]); } if (Request["WIDTH"] == null) { WriteError("mandatory WIDTH parameter is missing."); } else { this.Width = int.Parse(Request["WIDTH"]); } } if (Request["BBOX"] == null) { WriteError("mandatory BBOX parameter is missing."); } string[] bbox = Request["BBOX"].Split(",".ToCharArray()); if (bbox.Length != 4) { WriteError("Invalid BBOX parameter. Must consist of 4 elements of type double or integer"); } double MinX = double.Parse(bbox[0], _nhi); double MinY = double.Parse(bbox[1], _nhi); double MaxX = double.Parse(bbox[2], _nhi); double MaxY = double.Parse(bbox[3], _nhi); Envelope box = new Envelope(MinX, MinY, MaxX, MaxY); if (box.minx >= box.maxx || box.miny >= box.maxy) { WriteError("Invalid BBOX parameter. MinX must not be greater than MaxX, and MinY must not be greater than MaxY"); } this.BBOX = box; string LayerTag = "LAYERS"; if (this.Request == WMSRequestType.GetFeatureInfo) { LayerTag = "QUERY_LAYERS"; } if (Request[LayerTag] == null) { WriteError("mandatory LAYERS parameter is missing."); } else { String sLayers = Request[LayerTag]; if (LayerTag == "LAYERS") { this.Layers = sLayers.Split(",".ToCharArray()); } else if (LayerTag == "QUERY_LAYERS") { this.QueryLayers = sLayers.Split(",".ToCharArray()); } } if (Request["TRANSPARENT"] != null && Request["TRANSPARENT"].ToUpper() == "TRUE") { this.Transparent = true; } if (Request["BGCOLOR"] != null) { this.BgColor = ColorTranslator.FromHtml(Request["BGCOLOR"]); } if (Request["STYLES"] != null) { String[] styles = Request["STYLES"].Split(",".ToCharArray()); for (int i = 0; i < styles.Length; i++) { if (styles[i] != null && styles[i] != String.Empty) { WriteError("The monoGIS does not support named styles!.", "StyleNotDefined"); } } } if (Request["DPI"] != null) { this.dpi = double.Parse(Request["DPI"], _nhi); } if (this.Request == WMSRequestType.GetMap) { if (Request["SLD"] != null) { sldString = WebFunctions.DownloadXml(Request["SLD"]); if (sldString == null) { sldString = String.Empty; } } else if (Request["SLD_BODY"] != null) { sldString = Request["SLD_BODY"]; } } } } if (this.Request == WMSRequestType.GetFeatureInfo) { if (Request["QUERYLAYERS"] == null) { WriteError("mandatory QUERYLAYERS parameter is missing."); } else { String sQueryLayers = Request["QUERYLAYERS"]; this.QueryLayers = sQueryLayers.Split(",".ToCharArray()); } if (Request["X"] == null) { WriteError("mandatory X parameter is missing."); } else { this.FeatureInfoX = Convert.ToInt32(Request["X"]); if (this.FeatureInfoX > this.Width || this.FeatureInfoX < 0) { WriteError("invalid X parameter, must be greater than 0 and lower than Width parameter."); } } if (Request["Y"] == null) { WriteError("mandatory Y parameter is missing."); } else { this.FeatureInfoY = Convert.ToInt32(Request["Y"]); if (this.FeatureInfoY > this.Height || this.FeatureInfoY < 0) { WriteError("invalid Y parameter, must be greater than 0 and lower than HEIGHT parameter."); } } if (Request["FEATURECOUNT"] != null) { this.FeatureInfoMaxRows = Convert.ToInt32(Request["FEATURECOUNT"]); if (this.FeatureInfoMaxRows <= 0) { WriteError("invalid FEATURECOUNT parameter, must be greater than 0."); } } if (Request["INFOFORMAT"] != null) { switch (Request["INFOFORMAT"].ToLower()) { case "gml": case "application/vnd.ogc.gml": this.InfoFormat = WMSInfoFormat.gml; break; case "text/html": this.InfoFormat = WMSInfoFormat.html; break; case "text/xml": this.InfoFormat = WMSInfoFormat.xml; break; case "text/plain": this.InfoFormat = WMSInfoFormat.text; break; default: if (Request["INFOFORMAT"].ToLower().StartsWith("xsl/")) { this.InfoFormat = WMSInfoFormat.xsl; this.InfoFormatXsl = Request["INFOFORMAT"].ToLower(); } else { WriteError("invalid INFORMAT parameter, may be: text/html, GML or application/vnd.ogc.gml."); } break; } } else if (Request["INFO_FORMAT"] != null) { switch (Request["INFO_FORMAT"].ToLower()) { case "gml": case "application/vnd.ogc.gml": this.InfoFormat = WMSInfoFormat.gml; break; case "text/html": this.InfoFormat = WMSInfoFormat.html; break; case "text/xml": this.InfoFormat = WMSInfoFormat.xml; break; case "text/plain": this.InfoFormat = WMSInfoFormat.text; break; default: if (Request["INFO_FORMAT"].ToLower().StartsWith("xsl/")) { this.InfoFormat = WMSInfoFormat.xsl; this.InfoFormatXsl = Request["INFO_FORMAT"].ToLower(); } else { WriteError("invalid INFORMAT parameter, may be: text/html, GML or application/vnd.ogc.gml."); } break; } } } }