<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Problem generating token on C# in ArcGIS REST APIs and Services Questions</title>
    <link>https://community.esri.com/t5/arcgis-rest-apis-and-services-questions/problem-generating-token-on-c/m-p/1054924#M3838</link>
    <description>&lt;P&gt;Hi, &lt;SPAN&gt;I am trying to use the generateToken&lt;/SPAN&gt; to acces my service. When my function tries to communicate with the server the program crash and drop me this error.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;System.AggregateException was unhandled by user code&lt;BR /&gt;HResult=-2146233088&lt;BR /&gt;Message=Se han producido uno o varios errores.&lt;BR /&gt;Source=mscorlib&lt;BR /&gt;StackTrace:&lt;BR /&gt;en System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)&lt;BR /&gt;en System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)&lt;BR /&gt;en System.Threading.Tasks.Task`1.get_Result()&lt;BR /&gt;en Service.validacionExisteSolicitudSurveyService(String num) en d:\Users\juan.ruano\Documents\Visual Studio 2015\WebSites\xxxxxxxxxx\App_Code\Service.cs:línea 146&lt;BR /&gt;en SyncInvokevalidacionExisteSolicitudSurveyService(Object , Object[] , Object[] )&lt;BR /&gt;en System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]&amp;amp; outputs)&lt;BR /&gt;en System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp;amp; rpc)&lt;BR /&gt;InnerException:&lt;BR /&gt;HResult=-2146233088&lt;BR /&gt;Message=An error occurred while sending the request.&lt;BR /&gt;Source=mscorlib&lt;BR /&gt;StackTrace:&lt;BR /&gt;en System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)&lt;BR /&gt;en System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)&lt;BR /&gt;en System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()&lt;BR /&gt;en AuthenticationService.&amp;lt;AuthenticateService&amp;gt;d__1.MoveNext() en d:\Users\juan.ruano\Documents\Visual Studio 2015\WebSites\xxxxxxxx\App_Code\AuthenticationToken\AuthenticationService.cs:línea 77&lt;BR /&gt;--- Fin del seguimiento de la pila de la ubicación anterior donde se produjo la excepción ---&lt;BR /&gt;en System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)&lt;BR /&gt;en System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)&lt;BR /&gt;en System.Runtime.CompilerServices.TaskAwaiter.GetResult()&lt;BR /&gt;en Service.&amp;lt;DoWorkService&amp;gt;d__5.MoveNext() en d:\Users\juan.ruano\Documents\Visual Studio 2015\WebSites\xxxxxxxxxxxxxx\App_Code\Service.cs:línea 171&lt;BR /&gt;InnerException:&lt;BR /&gt;HResult=-2146233079&lt;BR /&gt;Message=Se ha terminado la conexión: Error inesperado de envío.&lt;BR /&gt;Source=System&lt;BR /&gt;StackTrace:&lt;BR /&gt;en System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext&amp;amp; context)&lt;BR /&gt;en System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar)&lt;BR /&gt;InnerException:&lt;BR /&gt;HResult=-2146232800&lt;BR /&gt;Message=No se puede escribir datos de en la conexión de transporte: Se ha forzado la interrupción de una conexión existente por el host remoto.&lt;BR /&gt;Source=System&lt;BR /&gt;StackTrace:&lt;BR /&gt;en System.Net.TlsStream.EndWrite(IAsyncResult asyncResult)&lt;BR /&gt;en System.Net.PooledStream.EndWrite(IAsyncResult asyncResult)&lt;BR /&gt;en System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)&lt;BR /&gt;InnerException:&lt;BR /&gt;ErrorCode=10054&lt;BR /&gt;HResult=-2147467259&lt;BR /&gt;Message=Se ha forzado la interrupción de una conexión existente por el host remoto&lt;BR /&gt;NativeErrorCode=10054&lt;BR /&gt;Source=System&lt;BR /&gt;StackTrace:&lt;BR /&gt;en System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)&lt;BR /&gt;en System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)&lt;BR /&gt;null&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;also here is my code.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public async Task AuthenticateService(int? desiredExpiration = null)
{
var tokenEndpoint =ServerUrl;

var data = new Dictionary&amp;lt;string, string&amp;gt;();
data["username"] = Usuario;
data["password"] = Password;
data["client"] = "requestedip";
var content = new FormUrlEncodedContent(data);

HttpRequestMessage msg = new HttpRequestMessage(HttpMethod.Post, "https://www.arcgis.com/sharing/rest/generateToken") { Content = content };
HttpClient httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Referrer = new Uri("https://arcgis.com");

var t = await httpClient.SendAsync(msg);
var s = await t.Content.ReadAsStringAsync();

}&lt;/LI-CODE&gt;&lt;P&gt;I have been stuck on this problem and try to solve it somehow but it seems to crush when the program try to communicate with the server.&lt;/P&gt;</description>
    <pubDate>Wed, 05 May 2021 21:23:43 GMT</pubDate>
    <dc:creator>JuanFranciscoRuano</dc:creator>
    <dc:date>2021-05-05T21:23:43Z</dc:date>
    <item>
      <title>Problem generating token on C#</title>
      <link>https://community.esri.com/t5/arcgis-rest-apis-and-services-questions/problem-generating-token-on-c/m-p/1054924#M3838</link>
      <description>&lt;P&gt;Hi, &lt;SPAN&gt;I am trying to use the generateToken&lt;/SPAN&gt; to acces my service. When my function tries to communicate with the server the program crash and drop me this error.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;System.AggregateException was unhandled by user code&lt;BR /&gt;HResult=-2146233088&lt;BR /&gt;Message=Se han producido uno o varios errores.&lt;BR /&gt;Source=mscorlib&lt;BR /&gt;StackTrace:&lt;BR /&gt;en System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)&lt;BR /&gt;en System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)&lt;BR /&gt;en System.Threading.Tasks.Task`1.get_Result()&lt;BR /&gt;en Service.validacionExisteSolicitudSurveyService(String num) en d:\Users\juan.ruano\Documents\Visual Studio 2015\WebSites\xxxxxxxxxx\App_Code\Service.cs:línea 146&lt;BR /&gt;en SyncInvokevalidacionExisteSolicitudSurveyService(Object , Object[] , Object[] )&lt;BR /&gt;en System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]&amp;amp; outputs)&lt;BR /&gt;en System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp;amp; rpc)&lt;BR /&gt;InnerException:&lt;BR /&gt;HResult=-2146233088&lt;BR /&gt;Message=An error occurred while sending the request.&lt;BR /&gt;Source=mscorlib&lt;BR /&gt;StackTrace:&lt;BR /&gt;en System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)&lt;BR /&gt;en System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)&lt;BR /&gt;en System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()&lt;BR /&gt;en AuthenticationService.&amp;lt;AuthenticateService&amp;gt;d__1.MoveNext() en d:\Users\juan.ruano\Documents\Visual Studio 2015\WebSites\xxxxxxxx\App_Code\AuthenticationToken\AuthenticationService.cs:línea 77&lt;BR /&gt;--- Fin del seguimiento de la pila de la ubicación anterior donde se produjo la excepción ---&lt;BR /&gt;en System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)&lt;BR /&gt;en System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)&lt;BR /&gt;en System.Runtime.CompilerServices.TaskAwaiter.GetResult()&lt;BR /&gt;en Service.&amp;lt;DoWorkService&amp;gt;d__5.MoveNext() en d:\Users\juan.ruano\Documents\Visual Studio 2015\WebSites\xxxxxxxxxxxxxx\App_Code\Service.cs:línea 171&lt;BR /&gt;InnerException:&lt;BR /&gt;HResult=-2146233079&lt;BR /&gt;Message=Se ha terminado la conexión: Error inesperado de envío.&lt;BR /&gt;Source=System&lt;BR /&gt;StackTrace:&lt;BR /&gt;en System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext&amp;amp; context)&lt;BR /&gt;en System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar)&lt;BR /&gt;InnerException:&lt;BR /&gt;HResult=-2146232800&lt;BR /&gt;Message=No se puede escribir datos de en la conexión de transporte: Se ha forzado la interrupción de una conexión existente por el host remoto.&lt;BR /&gt;Source=System&lt;BR /&gt;StackTrace:&lt;BR /&gt;en System.Net.TlsStream.EndWrite(IAsyncResult asyncResult)&lt;BR /&gt;en System.Net.PooledStream.EndWrite(IAsyncResult asyncResult)&lt;BR /&gt;en System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)&lt;BR /&gt;InnerException:&lt;BR /&gt;ErrorCode=10054&lt;BR /&gt;HResult=-2147467259&lt;BR /&gt;Message=Se ha forzado la interrupción de una conexión existente por el host remoto&lt;BR /&gt;NativeErrorCode=10054&lt;BR /&gt;Source=System&lt;BR /&gt;StackTrace:&lt;BR /&gt;en System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)&lt;BR /&gt;en System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)&lt;BR /&gt;null&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;also here is my code.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public async Task AuthenticateService(int? desiredExpiration = null)
{
var tokenEndpoint =ServerUrl;

var data = new Dictionary&amp;lt;string, string&amp;gt;();
data["username"] = Usuario;
data["password"] = Password;
data["client"] = "requestedip";
var content = new FormUrlEncodedContent(data);

HttpRequestMessage msg = new HttpRequestMessage(HttpMethod.Post, "https://www.arcgis.com/sharing/rest/generateToken") { Content = content };
HttpClient httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Referrer = new Uri("https://arcgis.com");

var t = await httpClient.SendAsync(msg);
var s = await t.Content.ReadAsStringAsync();

}&lt;/LI-CODE&gt;&lt;P&gt;I have been stuck on this problem and try to solve it somehow but it seems to crush when the program try to communicate with the server.&lt;/P&gt;</description>
      <pubDate>Wed, 05 May 2021 21:23:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-rest-apis-and-services-questions/problem-generating-token-on-c/m-p/1054924#M3838</guid>
      <dc:creator>JuanFranciscoRuano</dc:creator>
      <dc:date>2021-05-05T21:23:43Z</dc:date>
    </item>
    <item>
      <title>Re: Problem generating token on C#</title>
      <link>https://community.esri.com/t5/arcgis-rest-apis-and-services-questions/problem-generating-token-on-c/m-p/1054933#M3839</link>
      <description>&lt;P&gt;Maybe you should take a look at Dave Timmins &lt;A href="https://github.com/davetimmins/Anywhere.ArcGIS" target="_self"&gt;Anywhere.ArcGIS&lt;/A&gt; implementation. They solved a lot of token generations stuff using ArcGIS Online and ArcGIS Enterprise. I would start to inspect there &lt;A href="https://github.com/davetimmins/Anywhere.ArcGIS/blob/master/src/Anywhere.ArcGIS/TokenProvider.cs" target="_self"&gt;Anywhere.ArcGIS.TokenProvider&lt;/A&gt; implementation.&lt;/P&gt;&lt;P&gt;Enjoy.&lt;/P&gt;</description>
      <pubDate>Wed, 05 May 2021 21:38:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-rest-apis-and-services-questions/problem-generating-token-on-c/m-p/1054933#M3839</guid>
      <dc:creator>OSINT_ENGINEER</dc:creator>
      <dc:date>2021-05-05T21:38:31Z</dc:date>
    </item>
  </channel>
</rss>

