简体   繁体   中英

Exchange Web Services - The response received from the service didn't contain valid XML

I am attempting to connect to exchange web services (ews) on a exchange 2010 server. Here is the code I am using:

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Exchange.WebServices.Data;

namespace NDR_Processor
{
    class Program
{
    static void Main(string[] args)
    {
        ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
        service.Credentials = new System.Net.NetworkCredential("redacted", "redacted", "redacted");

        service.Url = new Uri("https://exchange.redacted.net/EWS/Exchange.asmx");

        System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

        FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, new ItemView(1000));

        foreach (Item item in findResults.Items)
        {
            Console.WriteLine(item.Subject);
            Console.WriteLine(item.Body);

        }
    }
}
}

However in doing so I get an error stating "The response received from the service didn't contain valid XML.". The inner exception indicates: {"Data at the root level is invalid. Line 1, position 1."}

I've tried hitting https://exchange.redacted.net/EWS/Exchange.asmx in a web browser, it prompts me to login and then I am presented with a valid XML document as far as I can tell. So I am at a loss as to why my application is choking.

Does anyone have any ideas for why this might be happening or how I can solve it?

Thanks Brad

service.Url = new Uri("https://mail.tencent.com/EWS/Exchange.asmx");

详细信息在这里: c#以编程方式从Exchange服务器读取电子邮件

I was experiencing the same issue as described in the following forum post: http://social.technet.microsoft.com/Forums/en-US/exchangesvrdevelopment/thread/e54c217f-28ff-4626-8ce8-a1242081f4d1/

(Essentially extra characters were being pre-pended and appended to the xml returned causing the error above)

If its any help - deleting and re-creating EWS virtual directory did not alleviate the problem.

I believe that perhaps our F5 load balancer or some intermediary device is inserting extra characters at the beginning or end of the XML.

When I changed my code to: service.Url = new Uri("https:// 192.168.xx /EWS/Exchange.asmx");

(Essentially using the internal IP address of our exchange server) the request worked just fine. So something outside of exchange is mangling the XML.

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