Select to view content in your preferred language

FeatureLayer ProxyUrl bug?

3373
11
06-25-2010 12:07 PM
BrooksShannon
Deactivated User
Hey guys,

I'm attempting to use a FeatureLayer with a proxy, and I'm having some problems.  Currently, I'm using the 2.0 public beta API, and I think the issues I'm seeing might be related to a bug, or bugs, in the API code.

If I specify that a FeatureLayer should use a proxy, like this:

<esri:FeatureLayer ID="MyFeatureLayer" 
                DisableClientCaching="True"
                Url="http://localhost/ArcGIS/rest/services/MyMapService/FeatureServer/0"
                ProxyUrl="http://localhost/MySLApp/proxy.ashx"
                Mode="OnDemand" 
                AutoSave="False"
                Color="Blue"
                OnDemandCacheSize="500"                 
                OutFields="NAME,IDENTIFIER,DLVRY_ADD"
                InitializationFailed="Layer_InitializationFailed"
                Initialized="Layer_Initialized">


I will receive the following exception, that I can capture in the layer's InitializationFailed event:

System.Net.WebException: The remote server returned an error: NotFound. ---> 
 System.Net.WebException: The remote server returned an error: NotFound.
 at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
 at System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClass5.<EndGetResponse>b__4(Object sendState)
 at System.Net.Browser.AsyncHelper.<>c__DisplayClass2.<BeginOnUI>b__0(Object sendState)
 --- End of inner exception stack trace ---
 at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
 at System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
 at System.Net.WebClient.GetWebResponse(WebRequest request, IAsyncResult result)
 at System.Net.WebClient.DownloadBitsResponseCallback(IAsyncResult result)


I spent a little time poking around with Firebug, and found out the following:

1) Things like tiled layers request the proxy page at
http://localhost/MySLApp/proxy.ashx?<theUrlItWants>
The FeatureLayer, however, requests the proxy page at
http://localhost/MySLApp/proxy.ashx<theUrlItWants>
during initialization - the key difference being the missing "?".

2) Post-initialization, the FeatureLayer goes back to requesting the proxy page at
http://localhost/MySLApp/proxy.ashx?<theUrlItWants>
  The "?" is there where it should be - this time.

3) The FeatureLayer, unlike other map services, won't let me use a relative path to the proxy page.  If I try using a relative path (say, "../proxy.ashx") I receive an exception claiming the URI kind can't be determined.  I'm forced to specify an absolute path, along with the protocol.

It could very well be the case that this is resolved in the 2.0 RC API - but the download link appears broken, so I can't find out. As it stands right now, however, I can't think of any way to make this work.  I could do something like use a proxy URL of
http://localhost/MySLApp/proxy.ashx?
(adding the "?" to the end) - but that makes any of the requests that come after layer initialization bomb.  (Which is what led me to believe that it's probably just a bug in the FeatureLayer's initialization - or something that occurs internally near the time of initialization, anyways.)

Does anyone from ESRI have any information that could help in this situation?

Thanks!
Brooks
0 Kudos
11 Replies
JayOckers
Deactivated User
During initialization a FeatureLayer will send two requests.  One for metadata and another to query and return features.   If using a proxy and defining the ProxyUrl property, both requests will be redirected through the proxy.


The issue I found is that the second request (the query) isn't formatted correctly when using a ProxyUrl.  It's missing the word query and only returns metadata.

Workaround for this was to modify the proxy to detect this type of bad request and inject the proper syntax.

We added this right after the token is appended to the localUri:

Regex regex = new Regex(@"MapServer/\d+(\?)returnGeometry", RegexOptions.Compiled);
if (regex.IsMatch(localUri))
{
     localUri = regex.Replace(localUri, (m) =>
          {
               string newVal = m.Groups[0].Value.Replace("?", "/query?");
               return newVal;
          }
     );
}
0 Kudos
JayOckers
Deactivated User
I'm having a similar problem using the identify task.

This is how the query should be formed:

MapServer/identify?geometryType=esriGeometryPoint&geometry={"x":959569.778050866,"y":3225324.48586893,"spatialReference":{"wkid":26715}}&returnGeometry=true&imageDisplay=1226,798,96&layers=visible&tolerance=2&mapExtent=954964.111157632,3221058.95804765,966234.665271614,3228394.93046442&f=json

But this is how it is being formed:

MapServer?geometryType=esriGeometryPoint&geometry={"x":959569.778050866,"y":3225324.48586893,"spatialReference":{"wkid":26715}}&returnGeometry=true&imageDisplay=1226,798,96&layers=visible&tolerance=2&mapExtent=954964.111157632,3221058.95804765,966234.665271614,3228394.93046442&f=json
0 Kudos