简体   繁体   中英

Exchange Web Services - The request failed. The remote server returned an error: (413) Request Entity Too Large

I have this simple code snippet, where I try to fetch folders from specific mailbox

ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;

ExchangeService service = new ExchangeService();

service.Credentials = new WebCredentials("ADMIN_USER@corp.contoso.com", "********");

Mailbox mb = new Mailbox("chris@corp.contoso.com");
FolderId fid = new FolderId(WellKnownFolderName.MsgFolderRoot, mb); 

// Set the URL.
service.Url = new Uri("https://<exchange>/EWS/Exchange.asmx");

var findResults = service.FindFolders(
    fid,
    new FolderView(int.MaxValue) { Traversal = FolderTraversal.Deep }
);

foreach(var result in findResults)
{
    //result.Load();
    Console.WriteLine(result.DisplayName);
}

It worked fine before, but today's morning it started to return this error

Microsoft.Exchange.WebServices.Data.ServiceRequestException: The request failed. The remote server returned an error: (413) Request Entity Too Large. ---> System.Net.WebException: The remote server returned an error: (413) Request Entity Too Large.

I tried different ways to solve it - mostly by increasing request entity size limit, but it does not help. I suppose code is fine, but VM or Exchange configuration need to be adjusted. Please advice how to solve it, thanks.

You shouldn't be doing this

new FolderView(int.MaxValue) { Traversal = FolderTraversal.Deep }

It won't work anyway because the maximum number of items that EWS will return will be 1000 anyway so you should implemented proper paging in your code https://docs.microsoft.com/en-us/exchange/client-developer/exchange-web-services/how-to-perform-paged-searches-by-using-ews-in-exchange else your code will fail when the Mail folder count exceeds 1000.

Before you adjust any server settings i would suggest you test EWS using something like the EWS Editor https://github.com/dseph/EwsEditor/releases if that works but your code doesn't then you know the problem lies at the source rather then the destination. There are very few instance where you should ever change IIS setting on a Exchange server for that type of request it shouldn't be necessary (maybe large attachments are the only one I can think off). So i would look at what else may have been recently installed on that server.

In my case, Exchange 2013 CU12, I tweaked the SSL settings of IIS and got a positive response from the Microsoft Remote Connectivity Analyzer .

Under the EWS subfolder of the Default Web Site, I changed the "SSL Settings" item "Client certificates" from "Accept" to "Ignore".

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM