Am using EWS API to connect Exchange server. The connection was established, but I didn’t receive any response.
Am getting exception “The response received from the service didn't contain valid XML.”
The inner Exception was “DTD is prohibited in this XML document.”
I didn’t get what is DTD?
I was getting your problem until (after MUCH trial and error):
set TraceEnabled to true, this will dump the back and forth messages to console.
I used the URL https://yourexchangeserver/EWS/Exchange.asmx
e.g. my work uses BPOS, in asia pacific region, so : https://red003.mail.apac.microsoftonline.com/EWS/Exchange.asmxRequest a specific service version e.g. ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1)
Step 1 got me past your first problem - it was giving the Outlook Web Access html page.
Step 2 let me see that it was then requesting 2010_Sp1, but that version wasn't supported.
Step 3 got "Hello world" working/sending.
Another note if you use that server, I couldn't get it to take any version except 2007 SP1, and thus, no AutoDiscovery of the URL.
public static string sendMail_BPOS_EWS()
{
try
{
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.UseDefaultCredentials = false;
service.Credentials = new WebCredentials("some_address@server.com", "password");
service.Url = new Uri("https://red003.mail.apac.microsoftonline.com/EWS/Exchange.asmx");
Console.WriteLine(service.Url);
service.TraceEnabled = true;
EmailMessage mail = new EmailMessage(service);
mail.From = new EmailAddress("from_address@server.com");
mail.ToRecipients.Add("to_address@server.com");
mail.Subject = "Email Subject";
mail.Body = "Email Body";
mail.Send();
return "sent";
}
catch (Exception ex)
{
return ex.ToString();
}
}
来源:https://stackoverflow.com/questions/8939038/am-getting-invalid-xml-as-a-response-from-ews-calls