I am converting some code that was written by a former employee using the Exchange Web Services API from Exchange 2007. When it was written, we had an on-premise Exchange 2007 Server. Now we have moved our email to Exchange Online and I want to use the Exchange Web Services for Exchange 2013 (API 2.1).
The old code used the ExchangeWebServices namespace and I want to use the Microsoft.Exchange.Webservices namespace in the new v2.1 API
None of the references from the old ExchangeWebServices namespace are defined in the new Microsoft.Exchange.Webservices so I need to refactor the code to match equivalent items in the new API.
One of the things I need to do is create a list of all of the Message IDs of the items in the Inbox for a specific user account. In the old code, this was used;
Private ExchangeBinding As New ExchangeServiceBinding
Public Sub New(ByVal UserName As String, ByVal Password As String, ByVal Domain As String, ByVal URL As String)
ExchangeBinding.Credentials = New NetworkCredential(UserName, Password, Domain)
ExchangeBinding.Url = URL
End Sub
Public Function GetInboxMessageIDs() As ArrayOfRealItemsType
Dim returnInboxMessageIds As ArrayOfRealItemsType = Nothing
Dim errMsg As String = String.Empty
'Create the request and specify the travesal type.
Dim FindItemRequest As FindItemType
FindItemRequest = New FindItemType
FindItemRequest.Traversal = ItemQueryTraversalType.Shallow
'Define which item properties are returned in the response.
Dim ItemProperties As ItemResponseShapeType
ItemProperties = New ItemResponseShapeType
ItemProperties.BaseShape = DefaultShapeNamesType.IdOnly
'Add properties shape to the request.
FindItemRequest.ItemShape = ItemProperties
'Identify which folders to search to find items.
Dim FolderIDArray(0) As DistinguishedFolderIdType
FolderIDArray(0) = New DistinguishedFolderIdType
FolderIDArray(0).Id = DistinguishedFolderIdNameType.inbox
'Add folders to the request.
FindItemRequest.ParentFolderIds = FolderIDArray
Try
'Send the request and get the response.
Dim FindItemResponse As FindItemResponseType
FindItemResponse = ExchangeBinding.FindItem(FindItemRequest)
'Get the response messages.
Dim ResponseMessage As ResponseMessageType()
ResponseMessage = FindItemResponse.ResponseMessages.Items
Dim FindItemResponseMessage As FindItemResponseMessageType
If ResponseMessage(0).ResponseClass = ResponseClassType.Success Then
FindItemResponseMessage = ResponseMessage(0)
returnInboxMessageIds = FindItemResponseMessage.RootFolder.Item
Else
'' Server error
Dim responseClassStr As String = [Enum].GetName(GetType(ExchangeWebServices.ResponseClassType), ResponseMessage(0).ResponseClass).ToString
Dim responseCodeStr As String = [Enum].GetName(GetType(ExchangeWebServices.ResponseCodeType), ResponseMessage(0).ResponseCode).ToString
Dim messageTextStr As String = ResponseMessage(0).MessageText.ToString
Dim thisErrMsg As String = String.Format("ExchangeWebServices Inbox Error: {0}, {1}, {2}", responseClassStr, responseCodeStr, messageTextStr)
errMsg = If(errMsg.Equals(String.Empty), String.Empty, errMsg & "; ") & thisErrMsg
End If
Catch ex As Exception
errMsg = If(errMsg.Equals(String.Empty), String.Empty, errMsg & "; ") & ex.Message
End Try
If Not errMsg.Equals(String.Empty) Then
returnInboxMessageIds = Nothing
Throw New System.Exception(errMsg)
End If
Return returnInboxMessageIds
End Function
The items in the old API namespace that are not referenced in the new API namespace are;
-ExchangeServiceBinding
-ArrayOfRealItemsType
-FindItemType
-ItemQueryTraversalType
-ItemResponseShapeType
-DefaultShapeNamesType
-DistinguishedFolderIdType
-DistinguishedFolderIdNameType
-FindItemResponseType
-ResponseMessageType()
-FindItemResponseMessageType
-ResponseClassType
Does anyone have any recommendations for achieving this result using the new API code?