C#环境下使用 Get 和Post 的方式访问WFS服务

软件开发环境:VS2010

地图服务器:GeoServer 2.3.1

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Text;

 

private void GetUrlData()

         {
             WebClient client = new WebClient();
             string rUrl = "http://10.14.1.34:8080/geoserver/wfs?service=WFS&version=1.0.0&request=getFeature&typeName=Shanxi:Toll&PROPERTYNAME=NAME,the_geom&FILTER=<Filter><PropertyIsEqualTo><PropertyName>KIND</PropertyName><Literal>8400</Literal></PropertyIsEqualTo></Filter>" ;
             //client.DownloadDataCompleted += new DownloadDataCompletedEventHandler(client_DownloadDataCompleted);
             byte [] ss = client.DownloadData( new Uri(rUrl));
             string result = Encoding.UTF8.GetString(ss);
         }
 
         private void PostUrlData()
         {
             string rUrl = "http://10.14.1.34:8080/geoserver/wfs" ;
             //将字符串转换成字节数组, 注意Encoding.UTF8这样才能支持中文查询
             byte [] postBy = Encoding.UTF8.GetBytes( this .WfsData());
             //初始化WebClient
             WebClient webClient = new WebClient();
             //webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
             webClient.Headers.Add( "Content-Type" , "application/xml;charset=UTF-8" );           
             webClient.Headers.Add( "ContentLength" , postBy.Length.ToString());
 
             //上传数据,返回页面的字节数组
             byte [] responseData = webClient.UploadData(rUrl, "POST" , postBy);
 
             // 将返回的将字节数组转换成字符串(HTML);
             string srcString = Encoding.UTF8.GetString(responseData);
         }
 
 
         private string WfsData()
         {
             var xmlPara = "<?xml version='1.0' encoding='UTF-8'?>"
             + "<wfs:GetFeature service='WFS' version='1.0.0' "
             + "xmlns:wfs='http://www.opengis.net/wfs' "
             + "xmlns:gml='http://www.opengis.net/gml' "
             + "xmlns:ogc='http://www.opengis.net/ogc' "
             + "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' "
             + "xsi:schemaLocation='http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/wfs.xsd'>"
             + "<wfs:Query typeName='Shanxi:Toll' srsName='EPSG:4326'>"
             
             //属性查询
             + "<ogc:Filter xmlns:ogc='http://www.opengis.net/ogc'>"
             + "<ogc:And><ogc:PropertyIsLike wildCard='*' singleChar='.' escape='!'>"
             + "<ogc:PropertyName>NAME</ogc:PropertyName>"
             + "<ogc:Literal>*收费站*</ogc:Literal>"
             + "</ogc:PropertyIsLike></ogc:And></ogc:Filter>"
 
             //空间查询
             //+ "<ogc:Filter>"
             //+ "<ogc:Intersects>"
             //+ "<ogc:PropertyName>the_geom</ogc:PropertyName>"
             //+ " <gml:Point srsName='http://www.opengis.net/gml/srs/epsg.xml#4326'>"
             //+ "<gml:coordinates>111.08158415999999,38.98932696</gml:coordinates>"
             //+ "</gml:Point>"
             //+ "</ogc:Intersects>"
             //+ "</ogc:Filter>"
 
             //后部分节点
             + "</wfs:Query>"           
             + "</wfs:GetFeature>" ;
 
             return xmlPara;
         }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值