Exchange Web Services - The response received from the service didn't contain valid XML

百般思念 提交于 2019-12-07 06:40:31

问题


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

        }
    }
}
}

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."}

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?

Thanks Brad


回答1:


service.Url = new Uri("https://mail.tencent.com/EWS/Exchange.asmx");

Details info is here: c# programmatically reading emails from the Exchange server




回答2:


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/

(Essentially extra characters were being pre-pended and appended to the xml returned causing the error above)

If its any help - deleting and re-creating EWS virtual directory did not alleviate the problem.

I believe that perhaps our F5 load balancer or some intermediary device is inserting extra characters at the beginning or end of the XML.

When I changed my code to: service.Url = new Uri("https://192.168.x.x/EWS/Exchange.asmx");

(Essentially using the internal IP address of our exchange server) the request worked just fine. So something outside of exchange is mangling the XML.



来源:https://stackoverflow.com/questions/11344400/exchange-web-services-the-response-received-from-the-service-didnt-contain-va

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