[OpenLayers-Users] asp.net wfs proxy...

John Cole john.cole at uai.com
Tue Apr 10 19:03:38 EDT 2007


If your working with asp.net and using the WFS tools, you'll find out that
you need to proxy your WFS requests through your web server.

Below is a very (and I mean VERY) simple one.  

Add a key to your app settings to hold the WFS url (or some other way to
store it).

Use it in a layer like:

layer_wfs = new OpenLayers.Layer.WFS( "WFS Markers",
                "WFSProxy.ashx?", {typename: "somelayer"},
                { 'buffer':0, featureClass: OpenLayers.Feature.WFS});


------------------------------------------------------------

<%@ WebHandler Language="C#" Class="WFSProxy" %>

using System;
using System.Web;
using System.Net;
using System.IO;
using System.Text;
using System.Configuration;

public class WFSProxy : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/xml";
        
        context.Response.Write(_WFS(string.Format("{0}{1}",
ConfigurationManager.AppSettings["WFS_url"],
context.Request.QueryString.ToString().Replace("&amp;", "&"))));
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

    private string _WFS(string url) {
        string s = "";
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

        using (HttpWebResponse response =
(HttpWebResponse)request.GetResponse()) {
            // Get the stream associated with the response.
            using (Stream receiveStream = response.GetResponseStream()) {

                // Pipes the stream to a higher level stream reader with the
required encoding format. 
                using (StreamReader sr = new StreamReader(receiveStream,
Encoding.UTF8)) {
                    s = sr.ReadToEnd();
                }

            }

            response.Close();
        }

        return s;

    }

}

There are already other proxies in the OL examples directory if you need a
cgi one.  This one could be modified to proxy WMS requests too, if you
wanted to wrap the asp.net security model around your WMS servers.

John

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.446 / Virus Database: 269.0.0/754 - Release Date: 4/9/2007
10:59 PM
 
This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the sender. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail.



More information about the Users mailing list