Search code examples
exceptionexchange-serverexchangewebservices

Internal Server Error on FindItems for Public Folders


I've a simple VB.NET application to get all items on a Public Contact Folder. I know that this code works for many years. We upgraded on our OnPremise Exchange 2013 to CU23 for a few month and installed the Hafnium patches (BTW: Our server was not compromised and is not attached directly to the internet).

I think after this upgrade (But I'm not pretty sure) we have the problem that the request "FindItems" on a PublicFolder "Kontakte (Global)" returns an Internal Server Error. Here is the code:

Dim objExchangeService As New ExchangeService

objExchangeService.Credentials = objCredentials
objExchangeService.Url = New Uri(strExchangeUrl)


Dim objFolderView As New FolderView(intBatchSize, intFoldersOffset)
Dim objFolders As FindFoldersResults = objExchangeService.FindFolders(WellKnownFolderName.PublicFoldersRoot, objFolderView)
Dim objGlobalContacts As Folder = objFolders.FirstOrDefault(Function(objFolder) "Kontakte (Global)".Equals(objFolder.DisplayName, StringComparison.InvariantCulture))

Dim objView As New ItemView(Int32.MaxValue)
objExchangeService.FindItems(objGlobalContacts.Id, objView) ' Exception here -> Internal Server Error

We got this Exception:

Microsoft.Exchange.WebServices.Data.ServiceResponseException: Interner Serverfehler. Fehler bei diesem Vorgang.
   bei Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ProcessWebException(WebException webException)
   bei Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(IEwsHttpWebRequest request)
   bei Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ValidateAndEmitRequest(IEwsHttpWebRequest& request)
   bei Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute()
   bei Microsoft.Exchange.WebServices.Data.ExchangeService.FindItems[TItem](IEnumerable`1 parentFolderIds, SearchFilter searchFilter, String queryString, ViewBase view, Grouping groupBy, ServiceErrorHandling errorHandlingMode)
   bei Microsoft.Exchange.WebServices.Data.ExchangeService.FindItems(FolderId parentFolderId, ViewBase view)

Has anybody an idea whats wrong?


Solution

  • I found the solution. In my case the InternalURL of the ActiveSyncVirtualDirectory was not preset. That means if I enter "Get-ActiveSyncVirtualDirectory" it returns nothing.

    I found the solution here: https://serverfault.com/questions/916154/virtual-directory-activesync-exchange-2010-its-there-its-not-there

    In my Active Directory there was no object "Microsoft-Server-ActiveSync (Default Web Site)" but in the IIS the website exists. I cannot create a new virtual directory because there exists an orphaned configration.

    I did this to remove the orphaned IIS configuration (https://serverfault.com/questions/916154/virtual-directory-activesync-exchange-2010-its-there-its-not-there - Second answer):

    OK I finally have this one resolved, I want to share the solution in case someone else runs into it. Everything that follows here requires full Admin rights.
    
    Please run from powershell (on the exchange server)
    
    $Site = [ADSI]"IIS://localhost/W3SVC/1/Root/Microsoft-Server-ActiveSync"
    
    and then run
    
    $site
    
    Result:
    distinguishedName:
    Path: {C:\Program Files\Microsoft\Exchange Server\V14\Client Access\Sync}
    
    Next run:
    
    $Site = [ADSI]"IIS://localhost/W3SVC/1/Root"
    $site.Delete("IIsWebVirtualDir","Microsoft-Server-ActiveSync")
    $site.SetInfo()
    
    This will remove the phantom virtual directory.
    
    Now run:
    
    iisreset
    
    Now run:
    
    New-activesyncvirtualdirectory -websitename "Default Web Site"
    
    it should recreate the new virtual directory.
    
    Run iisreset again, and edit the internal and external URL's
    
    Then go get yourself a cold one.
    

    After these steps I got no errors on the "Apps" Tab and my code works. I think during this problem occurs during the CU update.

    Best regards

    Rainer