Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 79901

problem to call Elastic search Geolocation into dynamics 365 using custom workflow

$
0
0

Hello All,

I am using Ms Dynamics 365 V9.2 on line

I am trying to get geolocation details from elastic Search and populate crm. I created a custom workflow which runs on create a contact entity or update some fields data and set gps details (latitude and longitude).

I am facing on an issue when i call Elastic search via httpclient. postAsync() it returns statucode Forbidden. But the same code in my console app works fine.

I call the below method in codeactivity Execute method.

Thanks for your help.

Ps:

Here is a part of my code.

public JToken LoadES(string addressCRM, string key, string url, ITracingService tracingService)
{

HttpClientHandler handler = new HttpClientHandler();
handler.UseProxy = true;
HttpClient _httpClient = new HttpClient(handler);
JToken gpsToken = null;
var bodydata = @"{'size': 1, 'query': {'match': { 'full_address': {'query':'" + addressCRM + "','fuzziness': 'AUTO'}}}}";
JsonSerializer jsonSerializer = JsonSerializer.CreateDefault();
using (var stream = new MemoryStream())
using (var streamWriter = new StreamWriter(stream, Encoding.UTF8))
using (var jsonWriter = new JsonTextWriter(streamWriter))
{
jsonSerializer.Serialize(jsonWriter, bodydata);
jsonWriter.Flush();
HttpContent body = new StreamContent(stream);
body.Headers.ContentType = new MediaTypeHeaderValue("application/json");
_httpClient.DefaultRequestHeaders.Add("Authorization", key);
// this response is not success . 
var response = _httpClient.PostAsync(url, body).Result; 

if (response.IsSuccessStatusCode)
{
tracingService.Trace("Success Post Async response.... ");

var result = response.Content.ReadAsStringAsync();
var res = result.Result;
if (!String.IsNullOrEmpty(res))
{
JObject jresponse = JObject.Parse(res);
gpsToken = jresponse["hits"]["hits"][0]["_source"]["gps"];
}
}
else {

tracingService.Trace("Post Async Failed.... " +response.ReasonPhrase);
}

}
return gpsToken;


}


Viewing all articles
Browse latest Browse all 79901

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>