Public 个文件夹的 FindItems 内部服务器错误

Internal Server Error on FindItems for Public Folders

我有一个简单的 VB.NET 应用程序来获取 Public 联系人文件夹中的所有项目。我知道这段代码可以使用很多年。我们将 OnPremise Exchange 2013 升级到 CU23 几个月,并安装了铪补丁(顺便说一句:我们的服务器没有受到损害,也没有直接连接到互联网)。

我认为在这次升级之后(但我不太确定)我们遇到了一个问题,即 Public 文件夹“Kontakte(全球)”returns 上的请求“FindItems” returns服务器错误。这是代码:

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

我们遇到了这个异常:

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)

有没有人知道出了什么问题?

如果您尝试只获取文件夹中的最后一项怎么办,例如

Dim objView As New ItemView(1)
objExchangeService.FindItems(objGlobalContacts.Id, objView)

你不应该这样做

Dim objView As New ItemView(Int32.MaxValue)

因为节流无论如何都会阻止您在默认情况下获得超过 1000 项,因此您应该进行分页,但我会首先测试尝试获取 1 项。您还可以使用 EWSEditor https://github.com/dseph/EwsEditor/releases 在您的代码执行的操作之外进行一些测试,这比更改您的代码更容易。

我用 ItemView(1) 试过了,但得到了同样的错误。我使用了 EWSEditor,但看不到任何从 public 文件夹中获取项目的选项。

同时查看了EWS文件夹的错误日志。我得到了异常:

   bei Microsoft.Exchange.Data.ApplicationLogic.Cafe.GlobalServiceUrls.GetInternalUrl[Service](String serverFqdn)   
   bei Microsoft.Exchange.Data.ApplicationLogic.Cafe.HttpProxyBackEndHelper.GetBackEndServiceUrlByServer[ServiceType](BackEndServer backEndServer)  
   bei Microsoft.Exchange.Data.ApplicationLogic.Cafe.BackEndLocator.CallWithExceptionHandling[T](Func`1 actualCall)   
   bei Microsoft.Exchange.Services.Core.EwsClientHelper.DiscoverEwsUrl(IMailboxInfo mailbox)   
   bei Microsoft.Exchange.Services.Core.RemotePublicFolderOperations.Execute[T](Boolean writeOperation  CallContext callContext  RemoteExecute`1 executeEWSOperation)   
   bei Microsoft.Exchange.Services.Core.RemotePublicFolderOperations.GetFolderReplica(CallContext callContext  Byte[] folderIdBytes)   
   bei Microsoft.Exchange.Services.Core.Types.IdConverter.ServerInfoFromIdHeaderInformation(CallContext callContext  IdHeaderInformation header  Boolean isHierarchyOperations)   
   bei Microsoft.Exchange.Services.Core.Types.ServiceObjectId.InitServerInfo(Boolean isHierarchicalOperation)    
   bei Microsoft.Exchange.Services.Core.Types.BaseRequest.EvaluateMailboxMetrics(List`1 ids  Boolean isHierarchicalOperation)   
   bei Microsoft.Exchange.Services.Core.Types.BaseRequest.Submit[T](AsyncCallback hostCallback  Object hostState)    
   bei AsyncInvokeBeginBeginFindItem(Object   Object[]   AsyncCallback   Object )    
   bei System.ServiceModel.Dispatcher.AsyncMethodInvoker.InvokeBegin(Object instance  Object[] inputs  AsyncCallback callback  Object state)   
   bei System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)   
   bei System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)    
   bei System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc)   
   bei System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet);
   FaultInnerException=Microsoft.Exchange.Services.Core.Types.InternalServerErrorException: Interner Serverfehler. 
   Fehler bei diesem Vorgang. ---> 

Microsoft.Exchange.Data.ApplicationLogic.VDirConfigurationMissingException: 
   Das virtuelle Clientzugriffsverzeichnis-Objekt mit InternalUrl gestempelt für den -Dienst konnte nicht gefunden werden. Letzter überprüfter Server: EXCHANGE. (MEANS: Could not locate Client Access Virtual Directory object with InternalUrl stamped for service)  
  
   bei Microsoft.Exchange.Data.ApplicationLogic.Cafe.GlobalServiceUrls.DiscoverUrlsIfNeeded()    
   bei Microsoft.Exchange.Data.ApplicationLogic.Cafe.GlobalServiceUrls.GetInternalUrl[Service](String serverFqdn)    
   bei Microsoft.Exchange.Data.ApplicationLogic.Cafe.HttpProxyBackEndHelper.GetBackEndServiceUrlByServer[ServiceType](BackEndServer backEndServer)    
   bei Microsoft.Exchange.Data.ApplicationLogic.Cafe.BackEndLocator.CallWithExceptionHandling[T](Func`1 actualCall)    
   bei Microsoft.Exchange.Services.Core.EwsClientHelper.DiscoverEwsUrl(IMailboxInfo mailbox)    
   bei Microsoft.Exchange.Services.Core.RemotePublicFolderOperations.Execute[T](Boolean writeOperation  CallContext callContext  RemoteExecute`1 executeEWSOperation)    
   bei Microsoft.Exchange.Services.Core.RemotePublicFolderOperations.GetFolderReplica(CallContext callContext  Byte[] folderIdBytes)    
   bei Microsoft.Exchange.Services.Core.Types.IdConverter.ServerInfoFromIdHeaderInformation(CallContext callContext  IdHeaderInformation header  Boolean isHierarchyOperations)    
   bei Microsoft.Exchange.Services.Core.Types.ServiceObjectId.InitServerInfo(Boolean isHierarchicalOperation)    
   bei Microsoft.Exchange.Services.Core.Types.BaseRequest.EvaluateMailboxMetrics(List`1 ids  Boolean isHierarchicalOperation)    
   bei Microsoft.Exchange.Services.Core.Types.BaseRequest.Submit[T](AsyncCallback hostCallback  Object hostState)    

我认为内部 URL 一定有问题,我检查了我们的 URL:

   Get-ActiveSyncVirtualDirectory (No Internal URL set)
   Get-AutodiscoverVirtualDirectory (No Internal URL set)
   Get-EcpVirtualDirectory (Internal URL set)
   Get-MapiVirtualDirectory (Internal URL set)
   Get-OabVirtualDirectory (Internal URL set)
   Get-OwaVirtualDirectory (Internal URL set)
   Get-PowerShellVirtualDirectory (Internal URL set)
   Get-WebServicesVirtualDirectory (Internal URL set)

也许这个错误属于:https://docs.microsoft.com/de-de/troubleshoot/dynamics-365/sales/issue-when-adding-to-outlook-error-when-deploying-dynamics-365-app-for-outlook - 因为我得到了同样的错误。我今天或明天晚上会检查网址。

我找到了解决方案。在我的例子中,ActiveSyncVirtualDirectory 的 InternalURL 没有预设。这意味着如果我输入“Get-ActiveSyncVirtualDirectory”,它 returns 什么都没有。

我在这里找到了解决方案:https://serverfault.com/questions/916154/virtual-directory-activesync-exchange-2010-its-there-its-not-there

在我的 Active Directory 中没有对象“Microsoft-Server-ActiveSync(默认网站)”,但在 IIS 中该网站存在。我无法创建新的虚拟目录,因为存在孤立的配置。

我这样做是为了删除孤立的 IIS 配置(https://serverfault.com/questions/916154/virtual-directory-activesync-exchange-2010-its-there-its-not-there - 第二个答案):

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.

完成这些步骤后,我在“应用程序”选项卡上没有发现任何错误,并且我的代码可以正常工作。我想这个问题发生在CU更新期间。

此致

雷纳