是否正在从EWS调用中获取无效的XML作为响应? [英] Am getting invalid XML as a response from EWS calls?

查看:156
本文介绍了是否正在从EWS调用中获取无效的XML作为响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用EWS API连接Exchange服务器.建立了连接,但是我没有收到任何回复.

Am using EWS API to connect Exchange server. The connection was established, but I didn’t receive any response.

正在获取异常从服务接收到的响应不包含有效的XML."

Am getting exception "The response received from the service didn't contain valid XML."

内部异常是此XML文档中禁止使用DTD".

The inner Exception was "DTD is prohibited in this XML document."

我没有得到什么是DTD?

I didn’t get what is DTD?

推荐答案

直到(经过多次尝试和错误之后)我才遇到您的问题:

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

  1. 将TraceEnabled设置为true,这会将来回消息转储到控制台.

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

我使用了URL https://yourexchangeserver/EWS/Exchange.asmx
例如我的工作使用的是亚太地区的BPOS,因此: https://red003.mail .apac.microsoftonline.com/EWS/Exchange.asmx

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

请求特定的服务版本,例如ExchangeService服务=新的ExchangeService(ExchangeVersion.Exchange2007_SP1)

Request a specific service version e.g. ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1)

第1步使我摆脱了第一个问题-它提供了Outlook Web Access html页面.
步骤2让我看到它当时正在请求2010_Sp1,但不支持该版本.
步骤3使"Hello world"可以正常工作/发送.

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.

如果要使用该服务器,请注意,除2007 SP1之外,我无法采用其他任何版本,因此该URL没有自动发现.

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();
            }
        }

这篇关于是否正在从EWS调用中获取无效的XML作为响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆