3

I am using the Esri proxy to avoid CORS issues as I am testing against clients data held on another domain.

The wierd issue I am having is that WFS data only seems to work via one route, whereas mapping data seems to need another.

I have hosted the proxy locally using IIS. The following works for the WFS layer (ie using esriConfig.defaults.io.proxyUrl)

esriConfig.defaults.io.proxyUrl = "/ESRI-Proxy/proxy.ashx"; 

    // *************************************************************
    // Add a WFS Layer
    // *************************************************************
    var url = "https://clientsServer/arcgis/services/TEST/MyMapService/MapServer/WFSServer";

    var opts = {
        "url": url,
        "version": "1.0.0",
        "name": "GGS_Existing_Cables",
        "wkid": 4326,
        "maxFeatures": 1000
      };

    var layer = new WFSLayer();
    layer.fromJson(opts);

    var map = new Map(getMapDivId(), {
        basemap: "gray",
        sliderorientation : "horizontal"
    });

    map.addLayer(layer);

enter image description here

However when I then bring in the mapping layers I get CORS warnings (including for the WFS layer).

The mapping code is as follows:

// *****************************************************************
    // * Create two ArcGISDynamicMapServiceLayer layers.
    // * 
    // * One shows the OpenStreetMap layer as a basemap. The other loads
    // *   pipeline map data off the west coast of Africa from iTechs
    // *   ArcGIS Server Instance.
    // *****************************************************************
    var imageParameters = new ImageParameters();
    imageParameters.format = "jpeg"; //set the image type to PNG24, note default is PNG8.

    //Takes a URL to a non cached map service.
    var westAfricaPipelineLayer = new ArcGISDynamicMapServiceLayer(geturlToWestAfricaPipelines(), {
     "opacity" : 0.5,
     "imageParameters" : imageParameters
    });

    var streetMapBaseLayer = new ArcGISDynamicMapServiceLayer("http://server.arcgisonline.com/arcgis/rest/services/world_street_map/mapserver", {
     "opacity" : 0.5,
     "imageparameters" : imageParameters
    });

    map.addLayer(westAfricaPipelineLayer);  
    map.addLayer(streetMapBaseLayer);

     // *****************************************************************
     // Add the Nile Delta WMS Layer
     // *****************************************************************
     var layer1 = new WMSLayerInfo({
         name: '1',
         title: 'Nile Delta'
     });

    var resourceInfo = {
        extent: new Extent(-126.40869140625, 31.025390625, -109.66552734375, 41.5283203125, {
        wkid: 4326
        }),
        layerInfos: [layer1]
    };

    var wmsLayer = new WMSLayer(geturlToNileDeltaWmsMap(), {
        resourceInfo: resourceInfo,
        visibleLayers: ['1']
    });

    map.addLayers([wmsLayer]);

enter image description here

However if I add the following, the mapping layers work but the WFS layer still stops working:

urlUtils.addProxyRule({
      urlPrefix: getiTechRestfulBaseUrl(),
      proxyUrl: getUrlToProxy()
    });

    urlUtils.addProxyRule({
      urlPrefix: getiTechWMSBaseUrl(),
      proxyUrl: getUrlToProxy()
    });

getUrlToProxy is as follows

const URL_TO_PROXY = "http://localhost/ESRI-Proxy/proxy.ashx";

I would have thought that they amount to the same thing, i.e. esriConfig.defaults.io.proxyUrl and urlUtils.addProxyRule?

I have either (hopefully not) found a bug, i'm doing something very stupid, or I am using the two proxy routes in an unsafe manner (or a combinataion of...).

0

1 Answer 1

2

The ESRI Documentation is great, but so generic in this chapter from my point of view.

You have always 2 possibilities, either to use a proxy url, your first solution; or define some proxy rules, your second solution. For your problem I guess the second one is a better approach because you do not need always a proxy, it is for some services.

Check the following:

  • Enter a "?" after the proxy url: const URL_TO_PROXY = "http://<your_host>/ESRI-Proxy/proxy.ashx?";
  • In order to use CORS both the browser and the target web server must support CORS. ArcGIS Server 10.1 supports CORS out of the box, but probably your WMS not. Visit enable-cors.org for detailed instructions.
  • If an application makes requests to an ArcGIS Server, esriRequest will automatically detect if that server supports CORS. However, if a server is known to support CORS, it is recommended that you configure your application manually by telling the API that a server supports CORS: esriConfig.defaults.io.corsEnabledServers.push("yourserver.com");

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.