public string Send(string service, string request, string InterpreterGUID, string user, string pwd) { string ret = WebFunctions.HttpSendRequest(_url + "/MapRequest/" + InterpreterGUID + "/" + service, "POST", Encoding.UTF8.GetBytes(request), user, pwd, this.Timeout * 1000); return(Encoding.UTF8.GetString(Encoding.Default.GetBytes(ret))); }
private string SendRequest_ServletExec(StringBuilder sb, string ServerName, string ServiceName, string CustomService) { // // Sollte beim GET_IMAGE Request auch das file Attribut im OUTPUT tag enthalten sein, // muss im esrimap_prop file (ServletExec/servlets/...) der Wert: // spatialServer.AllowResponsePath=True gesetzt werden (Standard ist false) // string theURL = ServerName; if (ServerName.IndexOf("http") != 0) { theURL = "http://" + theURL; } if (theURL.IndexOf("/", 10) == -1) { theURL += "/" + ServerUrl(ServerName); } if (theURL.IndexOf("?") == -1) { theURL += "?"; } if (theURL.IndexOf("?") != (theURL.Length - 1)) { theURL += "&"; } //string theURL = "http://" + ServerName + "/"+ServerUrl(ServerName)+"?ServiceName=" + ServiceName;// + "&ClientVersion=4.0"; if (ServiceName != "") { theURL += "ServiceName=" + ServiceName + "&ClientVersion=4.0"; } else { theURL += "ClientVersion=4.0"; } if (CustomService != "") { theURL += "&CustomService=" + CustomService; } if (CommaFormat != ',') { string temp = replaceComma(sb.ToString()); sb = new StringBuilder(); sb.Append(temp); } //System.Text.UTF8Encoding encoder=new UTF8Encoding(); //byte [] POSTbytes=encoder.GetBytes(sb.ToString()); byte[] POSTbytes = _encoding.GetBytes(sb.ToString()); return(WebFunctions.HttpSendRequest(theURL, "POST", POSTbytes, _user, _passwd, _encoding)); }
async static public Task <string> RefreshTokenAsync(string serviceUrl, string user, string password, string currentToken = "") { string currentParameter = currentToken; //lock (_refreshTokenLocker) { string dictKey = serviceUrl + "/" + user; if (_tokenParams.ContainsKey(dictKey) && _tokenParams[dictKey] != currentParameter) { return(_tokenParams[dictKey]); } else { int pos = serviceUrl.ToLower().IndexOf("/rest/"); string tokenServiceUrl = serviceUrl.Substring(0, pos) + "/tokens/generateToken"; //string tokenParams = $"request=gettoken&username={ user }&password={ password.UrlEncodePassword() }&expiration={ RequestTokenCache.TicketExpiration }&f=json"; string tokenParams = $"request=gettoken&username={ user }&password={ password.UrlEncodePassword() }&f=json"; string tokenResponse = String.Empty; while (true) { try { tokenResponse = WebFunctions.HttpSendRequest($"{ tokenServiceUrl }?{ tokenParams }"); break; } catch (WebException we) { if (we.Message.Contains("(502)") && tokenServiceUrl.StartsWith("http://")) { tokenServiceUrl = "https:" + tokenServiceUrl.Substring(5); continue; } throw we; } } if (tokenResponse.Contains("\"error\":")) { JsonError error = JsonConvert.DeserializeObject <JsonError>(tokenResponse); throw new Exception($"GetToken-Error:{ error.Error?.Code }\n{ error.Error?.Message }\n{ error.Error?.Details?.ToString() }"); } else { JsonSecurityToken jsonToken = JsonConvert.DeserializeObject <JsonSecurityToken>(tokenResponse); if (jsonToken.token != null) { _tokenParams.TryAdd(dictKey, jsonToken.token); return(jsonToken.token); } } } } return(String.Empty); }
async public override Task <bool> Refresh() { await base.Refresh(); try { ServerConnection service = new ServerConnection(ConfigTextStream.ExtractValue(_connectionString, "server")); //string axl = service.ServiceRequest("catalog", "<GETCLIENTSERVICES/>", "BB294D9C-A184-4129-9555-398AA70284BC", // ConfigTextStream.ExtractValue(_connectionString, "user"), // Identity.HashPassword(ConfigTextStream.ExtractValue(_connectionString, "pwd"))); string axl = WebFunctions.HttpSendRequest("http://" + ConfigTextStream.ExtractValue(_connectionString, "server") + "/catalog?format=xml", "GET", null, ConfigTextStream.ExtractValue(_connectionString, "user"), ConfigTextStream.ExtractValue(_connectionString, "pwd")); if (String.IsNullOrEmpty(axl)) { return(false); } XmlDocument doc = new XmlDocument(); doc.LoadXml(axl); foreach (XmlNode mapService in doc.SelectNodes("//SERVICE[@name]")) { MapServiceType type = MapServiceType.MXL; if (mapService.Attributes["servicetype"] != null) { switch (mapService.Attributes["servicetype"].Value.ToLower()) { case "mxl": type = MapServiceType.MXL; break; case "svc": type = MapServiceType.SVC; break; case "gdi": type = MapServiceType.GDI; break; } } base.AddChildObject(new MapServerServiceExplorerObject(this, mapService.Attributes["name"].Value, _connectionString, type)); } return(true); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); return(false); } }
public bool AddMap(string name, string mxl, string usr, string pwd) { string ret = WebFunctions.HttpSendRequest(_url + "/addmap/" + name, "POST", Encoding.UTF8.GetBytes(mxl), usr, pwd, this.Timeout * 1000); if (ret.ToString().ToLower().Trim() != "true") { LastErrorMessage = ret; return(false); } return(true); }
public bool RemoveMap(string name, string usr, string pwd) { string ret = WebFunctions.HttpSendRequest(_url + "/removemap/" + name, "GET", null, usr, pwd, this.Timeout * 1000); if (ret.ToString().ToLower().Trim() != "true") { LastErrorMessage = ret; return(false); } return(true); }
public string QueryMetadata(string service, string user, string password) { try { return(WebFunctions.HttpSendRequest(_url + "/getmetadata/" + service, "GET", null, user, password, this.Timeout * 1000)); } catch (Exception ex) { return("ERROR:" + ex.Message); } }
public bool UploadMetadata(string service, string metadata, string user, string password) { try { return(WebFunctions.HttpSendRequest(_url + "/setmetadata/" + service, "POST", Encoding.UTF8.GetBytes(metadata), user, password, this.Timeout * 1000).ToLower().Trim() == "true"); } catch (Exception ex) { return(false); } }
public List <MapService> Services(string user, string password) { List <MapService> services = new List <MapService>(); DateTime td = DateTime.Now; string axl = String.Empty; axl = WebFunctions.HttpSendRequest(_url + "/catalog", "POST", Encoding.UTF8.GetBytes("<GETCLIENTSERVICES/>"), user, password, this.Timeout * 1000); TimeSpan ts = DateTime.Now - td; int millisec = ts.Milliseconds; if (axl == "") { return(services); } XmlDocument doc = new XmlDocument(); doc.LoadXml(axl); foreach (XmlNode mapService in doc.SelectNodes("//SERVICE[@name]")) { MapService.MapServiceType type = MapService.MapServiceType.MXL; if (mapService.Attributes["servicetype"] != null) { switch (mapService.Attributes["servicetype"].Value.ToLower()) { case "mxl": type = MapService.MapServiceType.MXL; break; case "svc": type = MapService.MapServiceType.SVC; break; case "gdi": type = MapService.MapServiceType.GDI; break; } } services.Add(new MapService(mapService.Attributes["name"].Value, type)); } return(services); }
async public Task <bool> Open(gView.MapServer.IServiceRequestContext context) { string url = String.Empty; try { _isOpened = true; bool ret = true; if (_wfsDataset != null) { ret = _wfsDataset.Open(); } if (_class != null) { string param = "REQUEST=GetCapabilities&VERSION=1.1.1&SERVICE=WMS"; url = Append2Url(_connection, param); string response = WebFunctions.HttpSendRequest(url, "GET", null, ConfigTextStream.ExtractValue(_connectionString, "usr"), ConfigTextStream.ExtractValue(_connectionString, "pwd")); response = RemoveDOCTYPE(response); _class.Init(response, _wfsDataset); } _state = (ret) ? DatasetState.opened : DatasetState.unknown; return(ret); } catch (Exception ex) { await WMSClass.ErrorLogAsync(context, "GetCapabilities", url, ex); _class = null; _wfsDataset = null; return(false); } }
public WFSFeatureClass(WFSDataset dataset, string name, WMSClass.SRS srs) { _dataset = dataset; _name = name; _srs = srs; if (_srs.Srs.Count > 0) { _sRef = gView.Framework.Geometry.SpatialReference.FromID(_srs.Srs[_srs.SRSIndex]); } try { string param = "VERSION=1.0.0&REQUEST=DescribeFeatureType&TYPENAME=" + _name; if (_dataset._decribeFeatureType.Get_OnlineResource.IndexOf("&SERVICE=") == -1 && _dataset._decribeFeatureType.Get_OnlineResource.IndexOf("?SERVICE=") == -1) { param = "SERVICE=WFS&" + param; } string url = WMSDataset.Append2Url(_dataset._decribeFeatureType.Get_OnlineResource, param); string response = WebFunctions.HttpSendRequest(url, "GET", null); response = WMSDataset.RemoveDOCTYPE(response); XmlDocument schema = new XmlDocument(); schema.LoadXml(response); XmlSchemaReader schemaReader = new XmlSchemaReader(schema); _targetNamespace = schemaReader.TargetNamespaceURI; if (_targetNamespace == String.Empty) { return; } _fields = schemaReader.ElementFields(name, out _shapefieldName, out _geomtype); // Id Feld suchen foreach (IField field in _fields.ToEnumerable()) { if (field.type == FieldType.ID) { _idFieldname = field.name; break; } } // passendes feld suchen... //if (_idFieldname == String.Empty) //{ // foreach (IField field in _fields) // { // if (!(field is Field)) continue; // switch (field.name.ToLower()) // { // case "fdb_oid": // case "oid": // case "fid": // case "objectid": // case "featureid": // case "ogc_fid": // ((Field)field).type = FieldType.ID; // _idFieldname = field.name; // break; // } // if (_idFieldname != String.Empty) break; // } //} } catch { } }
async protected override Task <IFeatureCursor> FeatureCursor(IQueryFilter filter) { string response = ""; string srsName = _sRef != null ? _sRef.Name : String.Empty; if (filter is ISpatialFilter) { filter = SpatialFilter.Project(filter as ISpatialFilter, this.SpatialReference); ((ISpatialFilter)filter).FilterSpatialReference = this.SpatialReference; } if (_dataset._getCapabilities.Post_OnlineResource == String.Empty && _dataset._getCapabilities.Get_OnlineResource != String.Empty) { string param = "VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=" + this.Name + "&MAXFEATURES=10&FILTER="; if (_dataset._getCapabilities.Get_OnlineResource.IndexOf("&SERVICE=") == -1 && _dataset._getCapabilities.Get_OnlineResource.IndexOf("?SERVICE=") == -1) { param = "SERVICE=WFS&" + param; } string wfsFilter = await Filter.ToWFS(this, filter, _dataset._filter_capabilites, _dataset._gmlVersion); string url = _dataset._getFeature.Get_OnlineResource; response = WebFunctions.HttpSendRequest(url, "GET", null); } else if (_dataset._getCapabilities.Post_OnlineResource != String.Empty) { string url = _dataset._getFeature.Post_OnlineResource; if (_dataset._getCapabilities.Get_OnlineResource.IndexOf("&SERVICE=") == -1 && _dataset._getCapabilities.Get_OnlineResource.IndexOf("?SERVICE=") == -1) { url = WMSDataset.Append2Url(url, "SERVICE=WFS"); } string wfsFilter = GetFeatureRequest.Create(this, this.Name, filter, srsName, _dataset._filter_capabilites, _dataset._gmlVersion); response = WebFunctions.HttpSendRequest(url, "POST", Encoding.UTF8.GetBytes(wfsFilter)); } if (response == String.Empty) { return(null); } try { StringReader stringReader = new StringReader(response); XmlTextReader xmlReader = new XmlTextReader(stringReader); XmlDocument doc = new XmlDocument(); //doc.LoadXml(response); XmlNamespaceManager ns = new XmlNamespaceManager(doc.NameTable); ns.AddNamespace("GML", "http://www.opengis.net/gml"); ns.AddNamespace("WFS", "http://www.opengis.net/wfs"); ns.AddNamespace("OGC", "http://www.opengis.net/ogc"); ns.AddNamespace("myns", _targetNamespace); //XmlNode featureCollection = doc.SelectSingleNode("WFS:FeatureCollection", ns); //if (featureCollection == null) // featureCollection = doc.SelectSingleNode("GML:FeatureCollection", ns); //if (featureCollection == null) return null; return(new gView.Framework.OGC.GML.FeatureCursor2(this, xmlReader, ns, filter, _dataset._gmlVersion, _dataset._filter_capabilites)); } catch { } return(null); }
public ICursor PointQuery(gView.Framework.Carto.IDisplay display, gView.Framework.Geometry.IPoint point, ISpatialReference sRef, IUserData userdata) { if (display == null || point == null) { return(null); } IEnvelope dispEnvelope = display.Envelope; if (sRef != null) { ISpatialReference mySRef = SpatialReference.FromID(_srs.Srs[_srs.SRSIndex]); if (mySRef != null && !mySRef.Equals(sRef)) { // TODO: // Stimmt net ganz, eigentlich wird beim Projezieren aus dem // Envelope ein Polygon, auch der Punkt, der als X-Pixel, Y-Pixel // übergeben wird, sollte sich ändern... // --> World2Image stimmt nicht 100% // dispEnvelope = GeometricTransformer.Transform2D(dispEnvelope, sRef, mySRef).Envelope; } } double x = point.X, y = point.Y; display.World2Image(ref x, ref y); StringBuilder request = new StringBuilder("VERSION=1.1.1&REQUEST=GetFeatureInfo"); request.Append("&QUERY_LAYERS=" + this.Name); request.Append("&QUERYLAYERS=" + this.Name); request.Append("&LAYERS=" + this.Name); //request.Append("&LAYERS=" + this.Name); request.Append("&EXCEPTIONS=" + _exceptions.Formats[0]); request.Append("&SRS=" + _srs.Srs[_srs.SRSIndex]); request.Append("&WIDTH=" + display.iWidth); request.Append("&HEIGHT=" + display.iHeight); request.Append("&INFOFORMAT=" + _getFeatureInfo.Formats[_getFeatureInfo.FormatIndex]); request.Append("&INFO_FORMAT=" + _getFeatureInfo.Formats[_getFeatureInfo.FormatIndex]); request.Append("&BBOX=" + dispEnvelope.minx.ToString(_nhi) + "," + dispEnvelope.miny.ToString(_nhi) + "," + dispEnvelope.maxx.ToString(_nhi) + "," + dispEnvelope.maxy.ToString(_nhi)); request.Append("&X=" + (int)x); request.Append("&Y=" + (int)y); string response; if (_getFeatureInfo.Formats[_getFeatureInfo.FormatIndex].ToLower().StartsWith("xsl/")) { return(new UrlCursor(WMSDataset.Append2Url(_getFeatureInfo.Get_OnlineResource, request.ToString()))); } else { switch (_getFeatureInfo.Formats[_getFeatureInfo.FormatIndex].ToLower()) { case "text/plain": response = WebFunctions.HttpSendRequest(WMSDataset.Append2Url(_getFeatureInfo.Get_OnlineResource, request.ToString())); return(new TextCursor(response)); case "text/html": return(new UrlCursor(WMSDataset.Append2Url(_getFeatureInfo.Get_OnlineResource, request.ToString()))); case "text/xml": response = WebFunctions.HttpSendRequest(WMSDataset.Append2Url(_getFeatureInfo.Get_OnlineResource, request.ToString())); return(new RowCursor(Xml2Rows(response))); case "application/vnd.ogc.gml": response = WebFunctions.HttpSendRequest(WMSDataset.Append2Url(_getFeatureInfo.Get_OnlineResource, request.ToString())); return(new RowCursor(Gml2Rows(response))); } } return(null); }
public bool Open() { try { _elements.Clear(); string param = "REQUEST=GetCapabilities&VERSION=1.0.0&SERVICE=WFS"; string url = WMSDataset.Append2Url(_url, param); string response = WebFunctions.HttpSendRequest(url, "GET", null); response = WMSDataset.RemoveDOCTYPE(response); XmlDocument doc = new XmlDocument(); doc.LoadXml(response); XmlNamespaceManager ns = new XmlNamespaceManager(doc.NameTable); ns.AddNamespace("WFS", "http://www.opengis.net/wfs"); ns.AddNamespace("OGC", "http://www.opengis.net/ogc"); ns.AddNamespace("GML", "http://www.opengis.net/gml"); XmlNode CapabilitiesNode = doc.SelectSingleNode("WFS:WFS_Capabilities/WFS:Capability", ns); _getCapabilities = new GetCapabilities(CapabilitiesNode.SelectSingleNode("WFS:Request/WFS:GetCapabilities", ns), ns); _decribeFeatureType = new DescribeFeatureType(CapabilitiesNode.SelectSingleNode("WFS:Request/WFS:DescribeFeatureType", ns), ns); _getFeature = new GetFeature(CapabilitiesNode.SelectSingleNode("WFS:Request/WFS:GetFeature", ns), ns); XmlNode FeatureTypeListNode = doc.SelectSingleNode("WFS:WFS_Capabilities/WFS:FeatureTypeList", ns); _operations = new Operations(FeatureTypeListNode.SelectSingleNode("WFS:Operations", ns)); foreach (XmlNode featureTypeNode in FeatureTypeListNode.SelectNodes("WFS:FeatureType", ns)) { string name = ""; string title = ""; XmlNode nameNode = featureTypeNode.SelectSingleNode("WFS:Name", ns); XmlNode titleNode = featureTypeNode.SelectSingleNode("WFS:Title", ns); WMSClass.SRS srs = new WMSClass.SRS(featureTypeNode, ns, "WFS"); name = title = nameNode.InnerText; if (titleNode != null) { title = titleNode.InnerText; } WFSFeatureClass featureClass = new WFSFeatureClass(this, name, srs); //DatasetElement dselement = new DatasetElement(featureClass); ILayer dselement = LayerFactory.Create(featureClass); if (dselement == null) { continue; } dselement.Title = name; _elements.Add(dselement); } _filter_capabilites = new Filter_Capabilities(doc.SelectSingleNode("WFS:WFS_Capabilities/OGC:Filter_Capabilities", ns), ns); return(true); } catch (Exception ex) { string err = ex.Message; return(false); } }
public bool RemoveMap(string name, string usr, string pwd) { string ret = WebFunctions.HttpSendRequest(_url + "/removemap/" + name, "GET", null, usr, pwd, this.Timeout * 1000); return(ret.ToString().ToLower().Trim() == "true"); }