Ramesh
Ramesh

Reputation: 145

Am getting invalid XML as a response from EWS calls?

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?

Upvotes: 3

Views: 6130

Answers (1)

quick_dry
quick_dry

Reputation: 811

I was getting your problem until (after MUCH trial and error):

  1. set TraceEnabled to true, this will dump the back and forth messages to console.

  2. 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.asmx

  3. Request 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("[email protected]", "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("[email protected]");
                mail.ToRecipients.Add("[email protected]");
                mail.Subject = "Email Subject";
                mail.Body = "Email Body";

                mail.Send();
                return "sent";
            }
            catch (Exception ex)
            {
                return ex.ToString();
            }
        }

Upvotes: 5

Related Questions