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

Brad picture Brad · Jul 5, 2012 · Viewed 15k times · Source

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

Answer

dabuwang picture dabuwang · Jan 11, 2013
service.Url = new Uri("https://mail.tencent.com/EWS/Exchange.asmx");

Details info is here: c# programmatically reading emails from the Exchange server