I am getting a 400 bad request from getting the item from the portal on Xamarin Forms UWP

2155
12
06-28-2018 08:10 AM
Highlighted
New Contributor II

I already have code for Xamarin Forms iOS and Xamarin Forms Android that gets a config file from the ESRI portal and that works for both platforms.  I added the UWP component as we are now going to support UWP and I get a 400 bad request from the item.GetDataAsync() method.  I have already logged in and got a list of portal groups, I can select that group and the portal.createasync method appears to work but when I try to get the item with an id from the getdataasync() method that is when I get the 400 error.

When I put fiddler on the call I see the following error.

<?xml version="1.0" encoding="UTF-8"?>

<Error><Code>InvalidArgument</Code><Message>Only one auth mechanism allowed; only the X-Amz-Algorithm query parameter, Signature query string parameter or the Authorization header should be specified</Message><ArgumentName>Authorization</ArgumentName><ArgumentValue>Bearer XkcPcpODgq7bMLP3nLURAPrsXtM9gRbRcUaZf_igsXn5xn_5k0JC0TKuJBYkf2gUmvzeU9j7FE1PXYHR--Cr5hyKhf-cRkptCZp6VsTpXxPx6N3ZCXPKVRGoYVnPpPKVpZn71vMOCeuy_6Cn6J_Pxx2UQrwh5w31I0EGopXSPC5bKdLqvSKAEEs_69eDckTQ8Fl4CLGA2YaxfmmPxS5ZD4tKeLc6qUSvakHEEpv_awI1cA7N2FX1-sdpSPIa5BMG</ArgumentValue><RequestId>01BA2DD12883F913</RequestId><HostId>dvHaOQtMJgZzEOytj3oem4DkSFBLWN1mVgaZd39Fh4KTzVMOELkKGKtvG3ccb3g+dC5PnXekL98=</HostId></Error>

Ideas please?  Has any got this going on Xamarin Forms UWP.  I am using the 100.2.1 runtime.

Thanks in advance.

12 Replies
Highlighted
New Contributor II

I have also encountered this issue, also using the 100.2.1 runtime, and only on UWP (i.e. works fine for iOS and Android). It is happening when trying to take secured feature layers offline using a DownloadPreplannedOfflineMapJob. The requests to get the .tpk and .gdb files are both responding with "400 bad request" and have the same error message in Fiddler. This seems like a mis-configuration of the request authorizations (the request I am seeing in Fiddler uses all three of those auth mechanisms for the same request). Unfortunately because it's part of the job itself, we have no control over these requests.

Reply
0 Kudos
Highlighted
Regular Contributor II

Hi guys,

Have you managed to reproduce the issue reliably? If you have, could you please send us reproducer for this. This sounds not to be specifically related to a single job but a setup of portal item security and authentication. 

Reply
0 Kudos
Highlighted
New Contributor II

I can not get past this so I can reproduce it every time.  The same code works for iOS and Android.  I will try to create a repro example before the end of next week and contact support.  The code looks very simple it basically does a createasync on the portal and then gets the item via getdataasync.  I am assuming that it works for you.  I looked for an example on esri github examples but all of those use a public access portal.

Reply
0 Kudos
Highlighted
Regular Contributor II

Thanks Paul, 

Please include the setup up how your layers are created, what sharing and security options you have with the code. I do my testing mainly on WPF/Native UWP (non-Xamarin) but I haven't seen this happening before. Are you just using ArcGIS Online or is Enterprise/Server involved somehow?

Reply
0 Kudos
Highlighted
New Contributor II

I feel that this has nothing to do with layers at this point as its just trying to download the configuration file for ArcGIS online portal that is picked.  It is a really simple thing but it gets that 400 bad request when trying to get the config off the Esri portal online with the getdataasync() api call.  Do you have any UWP Xamarin forms examples where you have to authenticate and it then gets the configuration file off of the portal as that might be a good way to go?

Reply
0 Kudos
Highlighted
New Contributor II

Hi guys,

For us the issue occurs when the web map and layers we are attempting to download via the DownloadPreplannedOfflineMapJob are secured with an enterprise account. Making the web map and layers public (i.e. accessible to "Everyone" via the AGOL interface) actually does allow the requests to succeed, and downloads to occur, however, this will not be a viable solution for us in most cases.

Hope that helps in diagnosing the problem.

Highlighted
Frequent Contributor

Hi Paul and Matthew, 

Thank you for your feedback. I'm able to reproduce the bug and we'll look into getting it fixed in future releases of the API. 

It appears that GetDataAsync on secured portal item only work in UWP if DefaultChallengeHandler is used (setting OAuth is skipped). The underlying HttpClient is different and EnsureSuccessStatusCode in UWP may throw `Response status code does not indicate success: 400 (Bad Request)`. Apparently it's the Authorization header it doesn't like. 

You can use the following workaround, meanwhile. Only for UWP, remove authorization header for the GetDataAsync request. 

#if NETFX_CORE
    EventHandler<HttpRequestMessage> handler = (s, e) =>
    {
        if ((e.Headers?.Authorization?.Scheme == "Bearer") && e.RequestUri.OriginalString.Contains("/data"))
            e.Headers.Authorization = null;
    };
    ArcGISHttpClientHandler.HttpRequestBegin += handler;
#endif
    var data = await item.GetDataAsync();
#if NETFX_CORE
    ArcGISHttpClientHandler.HttpRequestBegin -= handler;
#endif
Highlighted
New Contributor II

This worked beautifully, thank you!

Reply
0 Kudos
Highlighted
New Contributor II

Hey Jennifer

Thank you for replying with a possible fix.  I have one question though we are currently using the 100.2.1 ArcGIS runtime - is that ArcGISHttpClientHandler available in that runtime ?  It looks to me like its only in the 100.3 runtime, am I correct in saying that?

Thanks

Paul

Reply
0 Kudos