Exchange Web服务-从服务收到的响应不包含有效的XML [英] Exchange Web Services - The response received from the service didn't contain valid XML
问题描述
我正在尝试连接到Exchange 2010服务器上的Exchange Web服务(ews).这是我正在使用的代码:
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);
}
}
}
}
但是这样做却出现错误,指出从服务接收到的响应不包含有效的XML.".内部异常指示:{根级别的数据无效.第1行,位置1."}
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."}
我尝试点击 https://exchange.redacted.net/EWS/Exchange.asmx在网络浏览器中,它提示我登录,然后据我所知向我提供有效的XML文档.所以我不知道为什么我的应用程序令人窒息.
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?
谢谢布拉德
推荐答案
I was experiencing the same issue as described in the following forum post: http://social.technet.microsoft.com/Forums/en-US/exchangesvrdevelopment/thread/e54c217f-28ff-4626-8ce8-a1242081f4d1/
(基本上,多余的字符会被预先添加并附加到返回的xml上,从而导致上述错误)
(Essentially extra characters were being pre-pended and appended to the xml returned causing the error above)
如果有帮助-删除并重新创建EWS虚拟目录并不能缓解问题.
If its any help - deleting and re-creating EWS virtual directory did not alleviate the problem.
我相信,也许我们的F5负载平衡器或某些中间设备正在XML的开头或结尾插入额外的字符.
I believe that perhaps our F5 load balancer or some intermediary device is inserting extra characters at the beginning or end of the XML.
当我将代码更改为:service.Url =新的Uri("https:// 192.168.x.x /EWS/Exchange.asmx");
When I changed my code to: service.Url = new Uri("https://192.168.x.x/EWS/Exchange.asmx");
(基本上使用我们的交换服务器的内部IP地址),该请求正常运行.因此,交换之外的事情正在破坏XML.
(Essentially using the internal IP address of our exchange server) the request worked just fine. So something outside of exchange is mangling the XML.
这篇关于Exchange Web服务-从服务收到的响应不包含有效的XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!