3

I know there are already lots of questions about this problem, I have read all of them but there is also nothing in my OpenLayers map, there are also no errors in debugger, can some one help me find the solution?

Here is what I have done, I have set up a proxy in MVC which is like this:

<%@ WebHandler Language="C#" Class="xDomainProxy" %>
using System; 
using System.Web; 
using System.Net; 
using System.IO; 
using System.Text; 
using System.Configuration; 

public class xDomainProxy : 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;
    }
}

I have tested this request URL and it responds:

http://localhost/WebApplication1/xDomainProxy.ashx?service=WFS&version=1.1.0&request=GetCapabilities&

This is GetCapabilities response:

<wfs:WFS_Capabilities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.opengis.net/wfs" xmlns:wfs="http://www.opengis.net/wfs" xmlns:ows="http://www.opengis.net/ows" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:it.geosolutions="http://www.geo-solutions.it" xmlns:cite="http://www.opengeospatial.net/cite" xmlns:NosazMohaseb="NosazMohaseb" xmlns:tiger="http://www.census.gov" xmlns:sde="http://geoserver.sf.net" xmlns:topp="http://www.openplans.org/topp" xmlns:sf="http://www.openplans.org/spearfish" xmlns:nurc="http://www.nurc.nato.int" version="1.1.0" xsi:schemaLocation="http://www.opengis.net/wfs http://127.0.0.1:8080/geoserver/schemas/wfs/1.1.0/wfs.xsd" updateSequence="90">
<ows:ServiceIdentification>
<ows:Title>GeoServer Web Feature Service</ows:Title>
<ows:Abstract>...</ows:Abstract>
<ows:Keywords>...</ows:Keywords>
<ows:ServiceType>WFS</ows:ServiceType>
<ows:ServiceTypeVersion>1.1.0</ows:ServiceTypeVersion>
<ows:Fees>NONE</ows:Fees>
<ows:AccessConstraints>NONE</ows:AccessConstraints>
</ows:ServiceIdentification>
<ows:ServiceProvider>...</ows:ServiceProvider>
<ows:OperationsMetadata>
<ows:Operation name="GetCapabilities">...</ows:Operation>
<ows:Operation name="DescribeFeatureType">...</ows:Operation>
<ows:Operation name="GetFeature">...</ows:Operation>
<ows:Operation name="GetGmlObject">...</ows:Operation>
<ows:Operation name="LockFeature">...</ows:Operation>
<ows:Operation name="GetFeatureWithLock">...</ows:Operation>
<ows:Operation name="Transaction">...</ows:Operation>
</ows:OperationsMetadata>
<FeatureTypeList>...</FeatureTypeList>
<ogc:Filter_Capabilities>...</ogc:Filter_Capabilities>
</wfs:WFS_Capabilities>

So it seems that proxy is configured and works fine; so this is my JavaScript code:

function AddWFSLayer() {
   var stylewfs_cur = new OpenLayers.Style({
        pointRadius: 3,
        fillColor: "#FF9000",
        strokeColor: "#FF9000",
        strokeWidth: 1,
        fillOpacity: 1,
        strokeOpacity: 1
    });
    var selStyle = new OpenLayers.Style({
        pointRadius: 5,
        fillColor: "#ffaa00",
        strokeColor: "#00DDFF",
        strokeWidth: 2,
        fillOpacity: 1,
        strokeOpacity: 1
    });
    var wfs = new OpenLayers.Layer.Vector("name", {
        strategies: [new OpenLayers.Strategy.Fixed(), saveStrategy],
        eventListeners: {
            'loadend': function (evt) {//THE LOADEND EVENT LISTENER - WHEN THE LAYER IS DONE LOADING...
                map.zoomToExtent(wfs.getDataExtent());//ZOOM TO ITS EXTENT!
            }//END OF THE LOADEND EVENT
        },//END OF THE eventListeners BLOCK
        projection: new OpenLayers.Projection("EPSG:900913"),
        protocol: new OpenLayers.Protocol.WFS({
            url: "/WebApplication1/xDomainProxy.ashx?",
            featurePrefix: "NosazMohaseb",
            featureType: "GParcel",
            geometryName: "NosazMohaseb:geom",
            featureNS: "NosazMohaseb",
            srsName: "EPSG:900913",
            version: "1.1.0"
        }),
        renderers: ["Canvas", "SVG", "VML"],
        styleMap: new OpenLayers.StyleMap({ 'default': stylewfs_cur, 'select': selStyle }),
        visibility: true
    });
    wfs.events.register("loadstart", wfs, function () { WaitWindow(); });
    wfs.events.register("loadend", wfs, function () { if (popup_Wait) { popup_Wait.destroy(); } });
    AddLAyerToMap(wfs);
}

function AddLAyerToMap(layer) {
    map.addLayer(layer);   
}

I don't know where am I doing wrong... Can someone help me?

I have checked all the similar questions but could not find my mistake... I am using OpenLayers 2 I can easily load WMS layer into my map.

This is response in firebug:

<ows:ExceptionReport xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ows="http://www.opengis.net/ows
/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0.0" xsi:schemaLocation="http
://www.opengis.net/ows/1.1 http://127.0.0.1:8080/geoserver/schemas/ows/1.1.0/owsAll.xsd">
  <ows:Exception exceptionCode="MissingParameterValue" locator="request">
    <ows:ExceptionText>Could not determine geoserver request from http request org.geoserver.platform
.AdvancedDispatchFilter$AdvancedDispatchHttpRequest@c48969</ows:ExceptionText>
  </ows:Exception>
</ows:ExceptionReport>

1 Answer 1

2

To enable use WFS layers..At first create a proxy

here it is

<%@ WebHandler Language="C#" Class="xDomainProxy" %>
using System;
using System.Web;
using System.Net;
using System.IO;
using System.Text;
using System.Configuration;

public class xDomainProxy : IHttpHandler
{

        public void ProcessRequest (HttpContext context) {
        System.Net.WebRequest req =
System.Net.WebRequest.Create(context.Request["url"]);
        if (req is System.Net.HttpWebRequest)
            ((System.Net.HttpWebRequest)req).UserAgent =
context.Request.UserAgent;
        req.ContentType = context.Request.ContentType;
        req.Method = context.Request.HttpMethod;

        int nRead = 0;
        byte[] baBuffer = new byte[BUFF_SIZE];
        if (req.Method == "POST")//The WebRequest object takes care of case for you
        {
            int nTmp = 0;
            while (nTmp < context.Request.ContentLength)
            {
                nRead = context.Request.InputStream.Read(baBuffer, 0,
BUFF_SIZE);
                if (nRead > 0)
                {
                    req.GetRequestStream().Write(baBuffer, 0, nRead);
                    nTmp += nRead;
                }
            }
            req.GetRequestStream().Flush();
            req.GetRequestStream().Close();
        }
        System.Net.WebResponse resp = req.GetResponse();
        context.Response.ContentType = resp.ContentType;
        System.IO.Stream strm = resp.GetResponseStream();
        nRead = strm.Read(baBuffer, 0, BUFF_SIZE);
        System.IO.Stream strmOut = context.Response.OutputStream;

        while (nRead != 0)
        {
            strmOut.Write(baBuffer, 0, nRead);
            nRead = strm.Read(baBuffer, 0, BUFF_SIZE);
        }

        strmOut.Flush();
        strmOut.Close();
    }

    private const int BUFF_SIZE = 8192;

    public bool IsReusable {
        get {
            return false;
        }
    }

}

it is named xDomainProxy.ashx

then add these codes in your javascript

//proxy host
OpenLayers.ProxyHost = '/WebApplication1/xDomainProxy.ashx?url=';

///

var wfs = new OpenLayers.Layer.Vector("name", {
        strategies: [new OpenLayers.Strategy.fixed(), saveStrategy],


        projection: new OpenLayers.Projection("EPSG:900913"),
        protocol: new OpenLayers.Protocol.WFS({

            url: "http://127.0.0.1:8080/geoserver/----/wfs?",
            featurePrefix: "workspacename",
            featureType: "Layername",
           // geometryName: "GeometryColumn",
            featureNS: "workspace uri",
           // srsName: "EPSG:900913",
            version: "1.0.0"
        }),
        renderers: ["Canvas", "SVG", "VML"],

        visibility: true
    });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.