Loading a map layer behind corporate proxy using ArcGIS Maps .Net for Android / MAUI / .Net 6.0

565
3
03-29-2023 12:56 PM
SnailsPace
New Contributor II

I am unable to load a map layer using ArcGIS Map 200.0 for MAUI under Android, while behind a corporate proxy. 

I have configured AndroidWifi to use the proxy, and verified it works by using Chrome to load a remote website.  Additionally, I can fetch the services json using .Net's HttpClient without issue (ie: https://services.arcgisonline.com/arcgis/rest/services/World_Street_Map/MapServer?f=pjson). 

However, attempting to load a layer will throw an exception:

System.Net.Sockets.SocketException (0xFFFDFFFF): hostname nor servname provided, or not known
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)

This exception does not occur if I run the same code (and connect to the same service) when NOT behind a proxy.  The layer will load without issue.

Even though it appears that .Net works with the configured proxy settings, my assumption is that I am not configuring ArcGIS Maps to use the proxy somehow.

Could someone enlighten me on how to do this?  I have searched the documentation, but appear to be missing it entirely.

(Interestingly, I do not have this issue using ArcGIS Maps with .Net 6.0 under Windows and WPF.)

3 Replies
dotMorten_esri
Esri Notable Contributor

 Additionally, I can fetch the services json using .Net's HttpClient without issue (ie:

Could you share the specific code you use to do that? It might give us some hints what is different between the Maps SDK's web stack and yours.

.NET 6 is using the SocketsHttpHandler, so try also with a few clients configured like this:
var client1 = new HttpClient(new SocketsHttpHandler());
or
var client2 = new HttpClient(new Esri.ArcGISRuntime.Http.ArcGISHttpMessageHandler());

0 Kudos
SnailsPace
New Contributor II

I've attached an example project which replicates the issue (and also shows .Net's HttpClient functioning).

To replicate:

1.  Configure a corporate proxy
2.  Open the solution and select Windows as a launch target
3.  Click the button.  You will get a popup which has the first 100 characters from the services JSON.
4.  The map layer loads fine
5.  Switch to Android as the launch target.
6.  Click the button.  You will get a popup which has the first 100 characters from the services JSON.
7.  This time the map layer will not load, and instead you'll get an exception displayed on screen.

 

Running the same code without a corporate proxy in place has no issue at all.  The exception only happens when behind a proxy and executing on Android.  Just to reiterate, I have configured the AndroidWifi to use the proxy; Chrome or Youtube pull data fine.

 

This is how we are creating our HttpClient instance:

System.Net.Http.HttpClient HttpClientInstance;
HttpClientHandler handler = new HttpClientHandler();
handler.ClientCertificateOptions = ClientCertificateOption.Manual;
// Ignore certificate issues for the moment
handler.ServerCertificateCustomValidationCallback = (httpRequestMessage, cert, cetChain, policyErrors) => { return true; };
HttpClientInstance = new HttpClient(handler) { Timeout = TimeSpan.FromSeconds(200) };

 

And this is how we fetch data using the HttpClient:

HttpResponseMessage response = await HttpClientInstance.GetAsync(servicesURL + "?f=pjson");
rawData = await response.Content.ReadAsByteArrayAsync();
encoding = System.Text.Encoding.UTF8;
string mapServerJSON = encoding.GetString(rawData);

0 Kudos
SnailsPace
New Contributor II

Just tested SocketsHttpHandler and ArcGISHttpMessageHandler (instead of HttpClientHandler)...  Both of those fail on Android while behind a corporate proxy (but work fine when not behind the proxy). 

0 Kudos