Error using webclient with gmail - exception

This is the code:
response =
Encoding.UTF8.GetString(
objClient.DownloadData("https://mail.google.com/mail/feed/atom")
);
And this is the error (exception) I get:
WebClient does not support current i/o operation
what could be the reason for that exception?

I believe the error you're talking about is "WebClient does not support *con*current I/O operations".
This exception is caused when you try to make multiple requests at the same time from a single WebClient instance. If you want to make concurrent requests, create a new WebClient instance.

Related

Amazon SQS Listener - Consuming message and setting attributes before failing the message

I've a fifo queue, and i'm using org.springframework.cloud.aws.messaging and here's what i'd like to do:
Consume the message
Try to handle it (inner logic)
If handles fails - write new attribute on the message (without sending the message again to the queue)
I don't want to send the messages to a new queue (i need to keep the order of the messages).
also, i don't want to use the deadletter queue for handling errors (same reason as above).
the reason i want to use message attributes is due to the fact that i need to implement in-house retry mechanism, meaning: when consuming the message i'll check the last_try_timestamp and if it's passed my validation then i'll try to handle it, else i'll throw an error.
(I know that the message will continue to be consumed until the MaxRetention and i'm fine with it)
Is something like that possible?
#SqsListener(value = "#{'${my.queue.fifo}'}", deletionPolicy = SqsMessageDeletionPolicy.ON_SUCCESS)
public void deadLetterQueueListener(#Headers Map<String, String> headers, String message) throws Exception {
log.info("consuming message");
if(!this.handleMessage(message)){
//Set message attributes (timestamp)
throw new Exception("Failed to handle message");
}
}
As far as I know there is no way to do it purely with SQS. If you modify the message attribute you would need to resend this message to propagate this change to SQS.
It can be implemented on the application side by storing metadata like last_try_timestamp in an external datasource like a DynamoDB where you could map message id to any metadata you need.

Which values can DocumentClientException.Error.Code have?

I want my data access layer to handle exceptions thrown by DocumentDB API provided via Microsoft.Azure.Documents.Client.DocumentClient class. For example, the optimistic concurrency check implemented using AccessCondition class, but others as well.
By looking at the exception thrown, the best way to recognize different DocumentClient-specific exceptions seems to be something like this:
try { ... }
catch (DocumentClientException exception)
when (exception.Error.Code == "Some magic here")
{
//let the user know how to recover from this..
}
I don't like such magic strings as they are not verifiable compile-time. It may contract a typo, or it may change on random moment with DocumentDB client/server changes, etc. Also, it is not clear which such magic codes I could/should be handling since I don't see the Microsoft.Azure.DocumentDB .net API containing any ErrorCodes enum or constants, nor find any list in documentation.
Where can I find a list of possible Error.Code values DocumentClient API can throw?
To make it even more confusing, the XmlDoc for DocumentClient.CreateDocumentAsync method suggest working instead on http status codes.
UPDATE: This question is not about Http status codes but DocumentClientException.Error.Code field as I assume the latter is more precise.
Where can I find a list of possible error codes values DocumentClient API can throw?
It's hard to find the completely list of error code that DocumentClinet API throw. The exception is depend on what your request.
For example, the optimistic concurrency check
Azure Cosmos DB uses ETags for handling optimistic concurrency.
When we retrieve a document from Azure Cosmos DB, it always contains an ETag property as apart of our document.
When we then want to send our request to replace a document, we can specify an AccessCondition with the ETag we received when we fetched out our document.
If the ETag we send is not current, the server will return a 412 Precondition Failed status code. In our .NET SDK, this is wrapped up in a DocumentClientException.
Here is an example that show the possible problems when the concurrency occurred.
By decompile the version 1.22.0 client, the code is set as a HttpStatusCode enum. I think all the possible values can be found here https://msdn.microsoft.com/en-us/library/system.net.httpstatuscode(v=vs.110).aspx then.
However, what really contains richer information for debug is the Error.Message. Might need to decompile the whole library to figure out, or wait for Microsoft to release the source codes, which is unlikely to happen since the latest update in github was 2 or 3 years ago.
public Error Error
{
get
{
if (this.error == null)
{
this.error = new Error()
{
Code = this.StatusCode.ToString(),
Message = this.Message
};
}
return this.error;
}
}
There is a list of the HTTP Status Codes for Azure Cosmos DB
I use the following code in my catch blocks
catch (DocumentClientException e)
{
var resp = new HttpResponseMessage
{
StatusCode = (HttpStatusCode) e.StatusCode,
Content = new StringContent(e.Message)
};
return resp;
}
Letting the user know how to handle the exception should be done on the client application.

Asynchronous download with HttpClient: The text associated with this error code could not be found

I intend to use the following code to download a file. It works when WIFI is available; but when there is no Wifi, I expect to catch the exception raised in the previousTask.get(). Unfortunately, catch in my code doesn't seem to catch the exception. The exception is HRESULT:0x80072F30 The text associated with this error code could not be found., by the way. Am I missing something like the exception is uncaughtable?
auto httpClient = ref new HttpClient();
auto get_operation = httpClient->GetAsync(ref new Uri(url), HttpCompletionOption::ResponseContentRead);
get_operation->Progress = progressHandler;
auto response = create_task(get_operation).then([](task<HttpResponseMessage^> previousTask)
{
try
{
return previousTask.get();
}
catch (Exception^ ex)
{
// Some how this does not catch
OutputDebugString(("Exception: " + ex->Message)->Data());
return (HttpResponseMessage^)nullptr;
}
}).get();
// At this point, I expect either a fully read response or response=nullptr
// Code to write to file is omitted
EDIT: ~~I tested the official Microsoft's HttpClient sample which apparently use similar code. Apparently, the same crash occurs in that app when there is no network connection. This sort of confirms that the defect is in the OS side and there's nothing one can do about it.~~
EDIT: It turns out that I thought the exception was not caught because Visual Studio pops up a dialog and I assume that means in reality the exception crashes the app i.e. when it is not launched via VS. I read the pop up message carefully and realize that VS prompts on every Exception thrown unless configured not to do so; pressing [Continue] button on the dialog goes to the catch clause. Launching app from Start menu poses no problem.
If this code is called from the UI thread then remove the get() call from the last line of this code. You can't do that in a UI thread.
Otherwise your code works fine for me with Airplane mode turned on; as expected I catch the exception in the handler. The exception has an HResult of 0x80072f30, which is documented on the MSDN page as ERROR_WINHTTP_NO_CM_CONNECTION

How to increase the time for timeout exception in windows phone?

In my windows phone app, i'm using HttpWebRequest for getting an image.But i'm getting exception.
When i checked out the stream, ReadTimeout exception has been thrown.
How can i increase the time?? because the data i'm getting is quite large.
According to the documentation, there is a Timeout property on HttpWebRequest that you can set.
Alternatively you can use Background file transfers, if your data is large.

EWS API Streaming subscription stops working

Created an windows service which saves all received and sent emails to my local drive and my service successfully does that.I have also resubscribed my streaming subscription onDisconnect event and Onerror event also.But my service stops responding after some time and there is no exception catched even though i have handled everything properly.Saw other forum and found the same issue people facing but there is not proper solution.
static private void OnDisconnect(object sender, SubscriptionErrorEventArgs args)
{
try
{
// Cast the sender as a StreamingSubscriptionConnection object.
StreamingSubscriptionConnection connection = (StreamingSubscriptionConnection)sender;
if (!connection.IsOpen)
connection.Open();
}
static void OnError(object sender, SubscriptionErrorEventArgs args)
{
// Cast the sender as a StreamingSubscriptionConnection object.
StreamingSubscriptionConnection connection = (StreamingSubscriptionConnection)sender;
if (!connection.IsOpen)
connection.Open();
}
Is this something to do with the Microsoft bug or it requires any settings on Exchange server for changing the limits for EWS subscription.
Even i checked below something related to throttling limit but no success:
http://msdn.microsoft.com/en-us/library/exchange/hh881884(v=exchg.140).aspx
Thanks a million in advance.
We have exactly same issue. And we do re-create whole subscription in OnError event just in case. It is also interesting that multiple application instances running on separate boxes exhibit identical behavior: at some point they just stop receiving notifications. Restarting any and all of them doesn't help; they do successfully subscribe but still no notifications other than OnDisconnect. Restarting Exchange Server is what really helps, though for a while.
I can see that the problem here is that you are trying to open the connection in the OnError handler. The problem here is that when OnError happen, the connection normally loses all the subscriptions, so you might need to consider creating the subscriptions again before opening them.