text: Q:
  
  Unable to post data into SQS from ASP.Net WebAPI 2
  
  I am trying to post some data to an AWS SQS queue from an ASP.Net webapi application.
  I am using AmazonSQSClient SendMessage() to do this. 
  It is working fine in console applications and windows services. However, when I try the same thing from a webapi application, the SendMessage() method thorows the following exception:
  [Amazon.Runtime.AmazonServiceException]
  {"Encountered a WebException (ConnectFailure), the request cannot be retried. Either the maximum number of retries has been exceeded (4/4) or the request is using a non-seekable stream."}
  Inner exception:
  {"An error occurred while sending the request."}, {"Unable to connect to the remote server"}
  Stack trace:
      at Amazon.Runtime.AmazonWebServiceClient.RetryOrThrow(WebRequestState state, Exception exception) at Amazon.Runtime.AmazonWebServiceClient.
  <InvokeConfiguredRequest>d__3`1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
    task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult() at Amazon.Runtime.AmazonWebServiceClient.
    <InvokeConfiguredRequest>d__3`1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
      task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult() at Amazon.Runtime.AmazonWebServiceClient.
      <InvokeConfiguredRequest>d__3`1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
        task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult() at Amazon.Runtime.AmazonWebServiceClient.
        <InvokeConfiguredRequest>d__3`1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
          task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult() at Amazon.Runtime.AmazonWebServiceClient.
          <InvokeConfiguredRequest>d__3`1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Amazon.SQS.AmazonSQSClient.SendMessage(SendMessageRequest request) at WebAPI.Alerts.Controllers.AlertsController.SendMessage(Queue
            queue, QueueRequest request) in c:\....\Controllers\AlertsController.cs:line 418
  
  Can anyone please help me in this?
  Adding some code for explaining the problem better:
    private QueueResponse SendMessage(Queue queue, QueueRequest request)
      {
          var queueResponse = new QueueResponse();
          try
          {
              if (queue != null)
              {
                  if (request != null)
                  {
                      using (this._queueServiceClient = this.CreateQueueServiceClient(queue.AccessKeyId, queue.SecretAccessKey))
                      {
                          var request1 = new SendMessageRequest()
                          {
                              DelaySeconds = request.DelaySeconds,
                              MessageBody = request.MessageBody,
                              QueueUrl = queue.Url
                          };
                          if (request.Attributes != null && request.Attributes.Count > 0)
                              request1.MessageAttributes = Enumerable.ToDictionary<MessageAttribute, string, MessageAttributeValue>((IEnumerable<MessageAttribute>)request.Attributes, (Func<MessageAttribute, string>)(a => a.Name), (Func<MessageAttribute, MessageAttributeValue>)(b => new MessageAttributeValue()
                              {
                                  DataType = b.DataType,
                                  StringValue = b.Value
                              }));
                          SendMessageResponse sendMessageResponse = this._queueServiceClient.SendMessage(request1);
                          if (sendMessageResponse == null)
                              throw new Exception("No response from the Queue");
                          queueResponse.ResponseCode = ((object)sendMessageResponse.HttpStatusCode).ToString();
                      }
                  }
              }
          }
          catch (Exception ex)
          {
              queueResponse.ResponseCode = ((object)HttpStatusCode.BadRequest).ToString();
              queueResponse.ErrorMessage = ex.Message;
          }
          return queueResponse;
      }
  
  UPDATE
  The issue seems to be related to the proxy settings. If fiddler is open in the system, then the webapi successfully accesses the queue. But it fails if fiddler is closed. 
  Final Update
  The issue was a bit silly after all. Webapi needed to use the system proxy.
  Adding
  <system.net>
      <defaultProxy enabled="true"></defaultProxy>
    </system.net>
  
  in the machine config resolved the issue. 
  
  A:
  
  I am just reposting the solution as the answer so that I can mark the issue as resolved.
  Webapi needed to use the system proxy while posting requests. Adding
  <system.net>
      <defaultProxy enabled="true"></defaultProxy>
    </system.net>
  
  in the machine config resolved the issue.
  
  