Am getting invalid XML as a response from EWS calls?

家住魔仙堡 提交于 2019-12-06 07:27:58

问题


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?


回答1:


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("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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!