HttpStatusCode from an EWS Managed API call RRS feed

  • Question

  • Hi there,

    I am in the process of converting a service from using WebDAV to the EWS Managed API for data access to an Exchange server (client is moving from Exchange 2007 to 2013). This service polls a mailbox folder, does some processing on emails that arrive there, and deletes or moves the emails once it is completed. The code I am working with has been using the status code from the HttpWebResponse returned from WebDAV requests for logging as well as handling WebExceptions (which have a response property for access to the request status).

    What I am wondering is whether the same status information is available for an EWS Managed API call - will calling Send() on a new EmailMessage always throw an exception if it is not successful? What are the common exception types to handle? So far I have simply been assuming success or exception and handling the WebException to get a status code if one of those is thrown. I will be starting to test against the new code shortly but it would be great if I had a better idea of whether I need to do more to handle call failures. I am quite new to developing against Exchange.



    Thursday, September 11, 2014 3:00 AM


All replies

  • No you shouldn't just rely on the http status code you need check the "ResponseClass of each response message" specifically see http://msdn.microsoft.com/en-us/library/office/dn771039(v=exchg.150).aspx. There are a number of errors that can happen where you will get a good https status but error code in the response so it import to process each and every response to ensure its okay.


    Thursday, September 11, 2014 4:38 AM
  • Thanks for the quick reply Glen.

    Unfortunately none of the Managed API calls I'm making return ServiceResponseCollections which means there are no response messages for me to refer to so I'll just have to rely on the exception handling to log what has gone wrong.

    The only ExchangeService method I'm calling is FindFolders() and I'm calling FindItems() on the Folder class and Send(), Move(), and Delete() on the EmailMessage class. The linked page does state that any methods that don't return a response collection will throw an exception if the method does not complete successfully so I guess that is good enough for me.

    But also in the page you've linked to it appears I should be handling ServiceResponseExceptions if I want to access the response (and its error code) to get more information about the cause of an exception.

    It's a shame that the last ServiceResponseCollection from an EWS call is not available on the ExchangeService like the HttpResponseHeaders are.

    Thanks again!

    Thursday, September 11, 2014 5:35 AM
  • The ServiceResponseCollection are important when you use the Batch method like CreateItems and MoveItems as you can have success and failures in the same batch operation. Personally I've never liked the methods that return void rather then a result, at that level you relying on the Managed API to bubble any exceptions to you which is generally safe to rely on.


    Friday, September 12, 2014 4:37 AM