AnsweredAssumed Answered

How do I locate sessionID from the Pro SDK?

Question asked by kmahoney01 on Jun 10, 2019
Latest reply on Jul 2, 2019 by kmahoney01

I am trying to use "Apply edits" feature service from my ArcGIS Pro Add-in.  See link.  Since I am working in a long transaction inside a branched version, I need the "sessionID" parameter when  POSTing to ArcGIS Server.  How do I retrieve this from the ArcGIS Pro SDK? See my feeble attempt below

 

I know that normally the client provides the GUID for the sessionID to ensure isolation, however it seems that ArcGIS Pro generates its own sessionID at startup (see screenshot below code snippet), and I would like to use that value for my service calls within the Pro client.

public static async void ApplyUpdatesToFeatureServer(IDictionary<Layer, List<Feature>> layerAttributeMap, bool useGlobalIds)
        {
            string format = "json";
            await QueuedTask.Run(async () => {
                //need this for current token, grab the token before every service call incase the token has expired/re-issued
                var active_portal = ArcGISPortalManager.Current.GetActivePortal();

                var keyset = layerAttributeMap.Keys;
                foreach (var key in keyset)
                {
                    if (key is FeatureLayer fLayer)
                    {
                      
                        string fServiceHost = fLayer.GetTable().GetDatastore().GetPath().Host;
                        var path = fLayer.GetTable().GetDatastore().GetPath();
                        string version = GetVersionFromConnectionString(fLayer.GetTable().GetDatastore().GetConnectionString());
                        var token = active_portal.GetToken();
                        string edits = buildEditsFromAttributes(layerAttributeMap);

                        string baseUri = path.Scheme + "://" + path.Host + ":" + path.Port;
                        var client = new EsriHttpClient();
                        client.BaseAddress = new Uri(baseUri);
                        var content = new FormUrlEncodedContent(new[]
                        {
                            //new KeyValuePair<string,string>("token", token),
                            //new KeyValuePair<string,string>("sessionId", ""),
                            new KeyValuePair<string,string>("f", format),
                            new KeyValuePair<string,string>("gdbVersion",version),
                            new KeyValuePair<string,string>("honorSequenceOfEdits","false"),
                            new KeyValuePair<string,string>("rollbackOnFailure","true"),
                            new KeyValuePair<string,string>("useGlobalIds",useGlobalIds.ToString()),
                            new KeyValuePair<string,string>("edits",edits)
                            //new KeyValuePair<string,string>("sessionId",key.)
                        });
                        var result = await client.PostAsync(path.LocalPath + "/applyEdits?token="+token, content);
                        string resultContent = await result.Content.ReadAsStringAsync();
                       
                        MessageBox.Show(resultContent);
                    }
                }
            });
        }

 

Outcomes