我的任务是编写一个移动应用程序(使用xamarin),允许您将Outlook设置为不在办公室。我发现的许多示例都在使用互操作,它不会在移动应用程序中构建。有人能推荐一种替代方法吗?
发布于 2014-06-05 21:46:30
您可以使用Exchange Web服务来执行此操作。
来自http://msdn.microsoft.com/en-us/library/office/aa563356(v=exchg.140).aspx:
static void SetOOF(ExchangeServiceBinding service)
{
// Identify the user mailbox for which to set OOF information.
EmailAddress emailAddress = new EmailAddress();
emailAddress.Address = "donhall@example.com";
emailAddress.Name = String.Empty;
UserOofSettings OOFSettings = new UserOofSettings();
// Identify the time that a user is OOF
Duration duration = new Duration();
duration.StartTime = DateTime.Now;
duration.EndTime = DateTime.Now.AddHours(4);
OOFSettings.Duration = duration;
// Identify the external audience.
OOFSettings.ExternalAudience = ExternalAudience.Known;
// Create the reply messages.
ReplyBody internalReply = new ReplyBody();
ReplyBody externalReply = new ReplyBody();
externalReply.Message = "This is my external OOF reply";
internalReply.Message = "This is my internal OOF reply";
OOFSettings.ExternalReply = externalReply;
OOFSettings.InternalReply = internalReply;
// Set OOF state.
OOFSettings.OofState = OofState.Enabled;
// Create the request.
SetUserOofSettingsRequest request = new SetUserOofSettingsRequest();
request.Mailbox = emailAddress;
request.UserOofSettings = OOFSettings;
try
{
// Send the request and return the response.
SetUserOofSettingsResponse response = service.SetUserOofSettings(request);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}发布于 2014-06-06 20:16:41
艾伦-感谢你的回复。我终于让它工作了,但这个库似乎已经被修改了,所以如果其他人需要它,这里是我的代码:
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);
service.Url = new Uri("https://<server>/EWS/Exchange.asmx");
EmailAddress emailAddress = new EmailAddress();
emailAddress.Address = "nick.wright@<domain>";
emailAddress.Name = String.Empty;
OofSettings OOFSettings = new OofSettings();
OOFSettings.Duration = new TimeWindow(DateTime.Now, DateTime.Now.AddDays(1));
OOFSettings.ExternalAudience = OofExternalAudience.All;
OofReply internalReply = new OofReply();
OofReply externalReply = new OofReply();
externalReply.Message = "This is my external OOF reply";
internalReply.Message = "This is my internal OOF reply";
OOFSettings.ExternalReply = externalReply;
OOFSettings.InternalReply = internalReply;
OOFSettings.State = OofState.Disabled;
try
{
service.SetUserOofSettings("nick.wright@<domain>", OOFSettings);
}
catch (Exception ex)
{
}我遇到了几个错误。首先,文档中的URL是不正确的,所以修复它:
exchange web service error - the remote server returned an error 405 method not allowed
其次,Exchange版本需要显式设置(虽然设置后,我可以将其设置为任何版本,并且它可以工作!?!)
http://social.technet.microsoft.com/Forums/exchange/en-US/df5c0c5e-1ea6-4ee9-824c-e8cb4930e291/ews-managed-api-error-exchange-server-doesnt-support-requested-version?forum=exchangesvrdevelopment
https://stackoverflow.com/questions/24061821
复制相似问题