Exchange EWS 托管 API - XML 中的意外标记

发布于 2024-10-02 12:37:45 字数 2276 浏览 7 评论 0原文

我正在尝试编写一个简单的示例程序来检查 Exchange 2010 服务器上的任何新邮件。据我所知,我的代码应该可以正常工作。

我按如下方式设置服务:

ExchangeService service = new ExchangeService();

service.Credentials = new WebCredentials("[email protected]", "password");

service.Url = new Uri("https://address/owa");

执行以下代码后:

        int unreadMail = 0;

        // Add a search filter that searches on the body or subject.
        List<SearchFilter> searchFilterCollection = new List<SearchFilter>();
        searchFilterCollection.Add(new SearchFilter.ContainsSubstring(ItemSchema.Subject, "Defense"));

        // Create the search filter.
        SearchFilter searchFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.Or, searchFilterCollection.ToArray());

        // Create a view with a page size of 50.
        ItemView view = new ItemView(50);

        // Identify the Subject and DateTimeReceived properties to return.
        // Indicate that the base property will be the item identifier
        view.PropertySet = new PropertySet(BasePropertySet.IdOnly, ItemSchema.Subject, ItemSchema.DateTimeReceived);

        // Order the search results by the DateTimeReceived in descending order.
        view.OrderBy.Add(ItemSchema.DateTimeReceived, SortDirection.Descending);

        // Set the traversal to shallow. (Shallow is the default option; other options are Associated and SoftDeleted.)
        view.Traversal = ItemTraversal.Shallow;

        // Send the request to search the Inbox and get the results.
        FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, searchFilter, view);

        // Process each item.
        foreach (Item myItem in findResults.Items)
        {
            if (myItem is EmailMessage)
            {
                if (myItem.IsNew) unreadMail++;

            }
        }

我收到此错误(在 FindItemResults 行上):

'>' is an unexpected token. The expected token is '"' or '''. Line 1, position 63.

这似乎是 API 实际生成的 XML 中的错误,我尝试了一些不同的代码(都是沿着同样的路线),但没有发现任何有效的东西。

有什么想法吗?当它直接来自 API 时,有点不知所措!

干杯,丹尼尔。

Im trying to write a simple sample program which checks for any new mail on an Exchange 2010 server. As far as I can tell, the code I've got should work fine.

I setup the service as follows:

ExchangeService service = new ExchangeService();

service.Credentials = new WebCredentials("[email protected]", "password");

service.Url = new Uri("https://address/owa");

Upon executing the following code:

        int unreadMail = 0;

        // Add a search filter that searches on the body or subject.
        List<SearchFilter> searchFilterCollection = new List<SearchFilter>();
        searchFilterCollection.Add(new SearchFilter.ContainsSubstring(ItemSchema.Subject, "Defense"));

        // Create the search filter.
        SearchFilter searchFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.Or, searchFilterCollection.ToArray());

        // Create a view with a page size of 50.
        ItemView view = new ItemView(50);

        // Identify the Subject and DateTimeReceived properties to return.
        // Indicate that the base property will be the item identifier
        view.PropertySet = new PropertySet(BasePropertySet.IdOnly, ItemSchema.Subject, ItemSchema.DateTimeReceived);

        // Order the search results by the DateTimeReceived in descending order.
        view.OrderBy.Add(ItemSchema.DateTimeReceived, SortDirection.Descending);

        // Set the traversal to shallow. (Shallow is the default option; other options are Associated and SoftDeleted.)
        view.Traversal = ItemTraversal.Shallow;

        // Send the request to search the Inbox and get the results.
        FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, searchFilter, view);

        // Process each item.
        foreach (Item myItem in findResults.Items)
        {
            if (myItem is EmailMessage)
            {
                if (myItem.IsNew) unreadMail++;

            }
        }

I get this error (on the FindItemResults line):

'>' is an unexpected token. The expected token is '"' or '''. Line 1, position 63.

This appears to be an error in the XML the API is actually generating, I've tried a few different lots of code (all along the same lines) and not found anything that works.

Any ideas? At a bit of a loss when it comes directly from the API!

Cheers, Daniel.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傲世九天 2024-10-09 12:37:45

没关系,修复它 - 需要将我的服务指向:

https://servername/ews/Exchange.asmx

并提供常规域登录详细信息,例如“用户名”、“密码”以便连接!

Nevermind, fixed it - needed to point my service to:

https://servername/ews/Exchange.asmx

and provide regular domain login details such as "username", "password" in order to connect!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文