Exchange server EWS服务器现在无法为该请求提供服务
我在使用ews托管api导出office 365帐户中的电子邮件时看到错误,“服务器现在无法处理此请求。请稍后重试。”为什么会发生此错误,以及可以采取哪些措施 我正在使用以下代码进行该工作:-Exchange server EWS服务器现在无法为该请求提供服务,exchange-server,office365,exchangewebservices,ews-managed-api,Exchange Server,Office365,Exchangewebservices,Ews Managed Api,我在使用ews托管api导出office 365帐户中的电子邮件时看到错误,“服务器现在无法处理此请求。请稍后重试。”为什么会发生此错误,以及可以采取哪些措施 我正在使用以下代码进行该工作:- _GetEmail = (EmailMessage)item; bool isread = _GetEmail.IsRead; sub = _GetEmail.Subject; fold = folder.Display
_GetEmail = (EmailMessage)item;
bool isread = _GetEmail.IsRead;
sub = _GetEmail.Subject;
fold = folder.DisplayName;
historicalDate = _GetEmail.DateTimeSent.Subtract(folder.Service.TimeZone.GetUtcOffset(_GetEmail.DateTimeSent));
props = new PropertySet(EmailMessageSchema.MimeContent);
var email = EmailMessage.Bind(_source, item.Id, props);
bytes = new byte[email.MimeContent.Content.Length];
fs = new MemoryStream(bytes, 0, email.MimeContent.Content.Length, true);
fs.Write(email.MimeContent.Content, 0, email.MimeContent.Content.Length);
Demail = new EmailMessage(_destination);
Demail.MimeContent = new MimeContent("UTF-8", bytes);
// 'SetExtendedProperty' used to maintain historical date of items
Demail.SetExtendedProperty(new ExtendedPropertyDefinition(57, MapiPropertyType.SystemTime), historicalDate);
// PR_MESSAGE_DELIVERY_TIME
Demail.SetExtendedProperty(new ExtendedPropertyDefinition(3590, MapiPropertyType.SystemTime), historicalDate);
if (isread == false)
{
Demail.IsRead = isread;
}
if (_source.RequestedServerVersion == flagVersion && _destination.RequestedServerVersion == flagVersion)
{
Demail.Flag = _GetEmail.Flag;
}
_lstdestmail.Add(Demail);
_objtask = new TaskStatu();
_objtask.TaskId = _taskid;
_objtask.SubTaskId = subtaskid;
_objtask.FolderId = Convert.ToInt64(folderId);
_objtask.SourceItemId = Convert.ToString(_GetEmail.InternetMessageId.ToString());
_objtask.DestinationEmail = Convert.ToString(_fromEmail);
_objtask.CreatedOn = DateTime.UtcNow;
_objtask.IsSubFolder = false;
_objtask.FolderName = fold;
_objdbcontext.TaskStatus.Add(_objtask);
try
{
if (counter == countGroup)
{
Demails = new EmailMessage(_destination);
Demails.Service.CreateItems(_lstdestmail, _destinationFolder.Id, MessageDisposition.SaveOnly, SendInvitationsMode.SendToNone);
_objdbcontext.SaveChanges();
counter = 0;
_lstdestmail.Clear();
}
}
catch (Exception ex)
{
ClouldErrorLog.CreateError(_taskid, subtaskid, ex.Message + GetLineNumber(ex, _taskid, subtaskid), CreateInnerException(sub, fold, historicalDate));
counter = 0;
_lstdestmail.Clear();
continue;
}
仅当尝试在office 365帐户中导出并且在outlook 2010、2013、2016等情况下正常工作时,才会发生此错误。通常在Exchange中超过EWS限制时会发生此错误。这是我的解释 确保您已经知道限制策略,并且您的代码符合它们。
如果您有服务器,您可以使用找到限制策略。解决您遇到的限制问题的一种方法是实现分页,而不是一次性请求所有项。你可以参考 例如:
using Microsoft.Exchange.WebServices.Data;
static void PageSearchItems(ExchangeService service, WellKnownFolderName folder)
{
int pageSize = 5;
int offset = 0;
// Request one more item than your actual pageSize.
// This will be used to detect a change to the result
// set while paging.
ItemView view = new ItemView(pageSize + 1, offset);
view.PropertySet = new PropertySet(ItemSchema.Subject);
view.OrderBy.Add(ItemSchema.DateTimeReceived, SortDirection.Descending);
view.Traversal = ItemTraversal.Shallow;
bool moreItems = true;
ItemId anchorId = null;
while (moreItems)
{
try
{
FindItemsResults<Item> results = service.FindItems(folder, view);
moreItems = results.MoreAvailable;
if (moreItems && anchorId != null)
{
// Check the first result to make sure it matches
// the last result (anchor) from the previous page.
// If it doesn't, that means that something was added
// or deleted since you started the search.
if (results.Items.First<Item>().Id != anchorId)
{
Console.WriteLine("The collection has changed while paging. Some results may be missed.");
}
}
if (moreItems)
view.Offset += pageSize;
anchorId = results.Items.Last<Item>().Id;
// Because you’re including an additional item on the end of your results
// as an anchor, you don't want to display it.
// Set the number to loop as the smaller value between
// the number of items in the collection and the page size.
int displayCount = results.Items.Count > pageSize ? pageSize : results.Items.Count;
for (int i = 0; i < displayCount; i++)
{
Item item = results.Items[i];
Console.WriteLine("Subject: {0}", item.Subject);
Console.WriteLine("Id: {0}\n", item.Id.ToString());
}
}
catch (Exception ex)
{
Console.WriteLine("Exception while paging results: {0}", ex.Message);
}
}
}
使用Microsoft.Exchange.WebServices.Data;
静态无效页面搜索项(ExchangeService服务,WellKnownFolderName文件夹)
{
int pageSize=5;
整数偏移=0;
//请求比实际页面大小多一项。
//这将用于检测结果的变化
//分页时设置。
ItemView视图=新的ItemView(页面大小+1,偏移量);
view.PropertySet=newpropertyset(ItemSchema.Subject);
view.OrderBy.Add(ItemSchema.DateTimeReceived,SortDirection.Descending);
view.Traversal=ItemTraversal.Shallow;
bool-moritems=true;
ItemId anchorId=null;
while(更多项目)
{
尝试
{
FindItemsResults=service.FindItems(文件夹,视图);
moreItems=结果。MoreAvailable;
if(moreItems&&anchorId!=null)
{
//检查第一个结果以确保它匹配
//上一页的最后一个结果(锚定)。
//如果没有,那意味着添加了一些内容
//或自开始搜索后已删除。
if(results.Items.First().Id!=anchorId)
{
WriteLine(“分页时集合已更改。可能会丢失某些结果。”);
}
}
如果(更多项目)
view.Offset+=页面大小;
anchorId=results.Items.Last().Id;
//因为你在结果的末尾加了一项
//作为锚,您不想显示它。
//将要循环的数字设置为之间的较小值
//集合中的项目数和页面大小。
int displayCount=results.Items.Count>pageSize?pageSize:results.Items.Count;
对于(int i=0;i
哪里定义了_destination。@Seabizkit我在全局级别定义了destination,而不是在函数级别。请您解释一下如何使用c#中的ews定义限制策略??