none
[EWS] [VB.net] - Get Responses from Bulk Update RRS feed

  • Question

  • Hi,

    Am writing an app which adds appointments to user diaries based on external data. Can get everything to write back, but struggling with service responses.

    As I am updating lots of records, I am using CreateItems for bulk updates. This is giving me a ServiceResponseCollection with the responses for each operation. What I can't find is how to link these responses back to the original request.

                Try
                    LogFile.WriteLogLine("Save Create Changes Called", True)
    
                    'Check if there are actually any items to Create
                    If m_CreateItems.Count = 0 Then
                        LogFile.WriteLogLine("No Items to Create")
                        Exit Sub
                    End If
    
                    'Create a Response Collection
                    Dim Responses As ServiceResponseCollection(Of ServiceResponse)
                    Responses = ExchangeService.CreateItems(m_CreateItems, Nothing, MessageDisposition.SaveOnly, SendInvitationsMode.SendToNone)
    
                    'Log a summary of the responses
                    LogFile.WriteLogLine("Save Create Items Complete - Success: " & Responses.Where(Function(r) r.Result = ServiceResult.Success).Count & ". Warnings: " & Responses.Where(Function(r) r.Result = ServiceResult.Warning).Count & ". Errors: " & Responses.Where(Function(r) r.Result = ServiceResult.Error).Count)
    
                    'Log the individual errors
                    If Responses.Where(Function(r) r.Result = ServiceResult.Error).Count > 0 Then
                        For Each R In Responses.Where(Function(a) a.Result = ServiceResult.Error)
                            LogFile.WriteLogLine(R.ErrorMessage)
                        Next
                    End If
    
                Catch ex As Exception
                    'Catch exceptions
                    LogFile.WriteLogLine("Error Creating Items: " & ex.Message)
    
                End Try

    Ideally what I want to do is be able to go through all the responses and find out which item errored so that it can be logged. At the minute all I can is find out that something errored.

    I have seen the GetItemResponse option, but can't work out how to link that into the code above.

    Any suggestions from anyone?


    Craig.



    • Edited by Craig Tolley Friday, October 18, 2013 11:32 AM Followed name convesntion for title
    Friday, October 18, 2013 11:21 AM

Answers

  • Hello Craig,

    I can only see 2 ways to do this:

    1) Remember the order in which you sent the items to be created (I believe the order would be consistent, Glen will likely know for sure whether that is true or not), then compare with result.
    2) Try reading the created items, the ones you don't get will be the ones that failed their creation.

    Cheers,
    Fred


    There's no place like 127.0.0.1

    • Marked as answer by Craig Tolley Friday, October 18, 2013 1:39 PM
    Friday, October 18, 2013 12:06 PM

All replies

  • Hello Craig,

    I can only see 2 ways to do this:

    1) Remember the order in which you sent the items to be created (I believe the order would be consistent, Glen will likely know for sure whether that is true or not), then compare with result.
    2) Try reading the created items, the ones you don't get will be the ones that failed their creation.

    Cheers,
    Fred


    There's no place like 127.0.0.1

    • Marked as answer by Craig Tolley Friday, October 18, 2013 1:39 PM
    Friday, October 18, 2013 12:06 PM
  • Thanks Fred,

    That's all I could think of too, but thought I must be missing something really obvious. Seems a strange omission to not be able to match requests to responses, but probably done on purpose.

    Would be good to know if the responses are definitely ordered consistently. If they are then that will be the solution.

    For option 2, I think it would be less overhead if I created the items one at a time, as it would be less overall calls to EWS, but might be worth a test to see what the actual impact is.

    Cheers,


    Craig.

    Friday, October 18, 2013 12:12 PM
  • Hello Craig,

    option 2 would have far less calls than creating items individually, I'd say. Simply tag them with a custom extended property, then bulk-request (ExchangeService.FindItems) items where the property exists (or if you do this many times, generate a unique text value at the beginning of the operation - datetime maybe - and search the items where it is that unique value).

    Cheers,
    Fred


    There's no place like 127.0.0.1


    • Edited by FWN Friday, October 18, 2013 12:21 PM
    Friday, October 18, 2013 12:20 PM
  • As I already have a custom extended property, that will be easy.

    Thanks for the help.


    Craig.

    Friday, October 18, 2013 1:40 PM