Exchangeservice (EWS) error: the response received ed from the service didn't contain valid XML.

Source: Internet
Author: User

When you use exchangeservice (EWS) to connect to the exchange mail server, the following error occurs:

The response received ed from the service didn't contain valid XML. Its innerexception is: the expected XML node type was xmldeclaration, but the actual type is element. The source code is as follows:
// Connect to the server exchangeservice service = new exchangeservice (exchangeversion. exchange2007_sp1); service. credentials = new networkcredential ("***", "***", "***"); service. autodiscoverurl ("***"); // get the email list (emails in the inbox) finditemsresults <item> findresults = service. finditems (wellknownfoldername. inbox, new itemview (10); foreach (item in findresults. items) {// obtain the specific email object emailmessage email = emailmessage. BIND (SE Rvice, item. ID); // determine whether the attachment is a file if (! (Email. attachments [0] Is fileattachment) continue; fileattachment = Email. attachments [0] As fileattachment; fileattachment. load ("C: \ temp \" + fileattachment. name); // mark as read email. isread = true; // submit the email changes to the server email. update (conflictresolutionmode. alwaysoverwrite );}

I checked some information and did not find the specific reason. I tried many methods and finally changed the code as follows:

// Connect to the server exchangeservice service = new exchangeservice (exchangeversion. exchange2007_sp1); service. credentials = new networkcredential ("User Name", "password", "Domain"); service. autodiscoverurl ("your mailbox"); service. url = new uri ("here is your email service address (ending with asmx)"); // get the mail list (emails in the inbox) finditemsresults <item> findresults = service. finditems (wellknownfoldername. inbox, new itemview (10); foreach (item in findresults. items) {// get Obtain the specific email object emailmessage email = emailmessage. BIND (Service, item. ID); // determine whether the attachment is a file if (! (Email. attachments [0] Is fileattachment) continue; fileattachment = Email. attachments [0] As fileattachment; fileattachment. load ("C: \ temp \" + fileattachment. name); // mark as read email. isread = true; // submit the email changes to the server email. update (conflictresolutionmode. alwaysoverwrite );}

This time, you will be charged normally. After adding the URL, you will solve the problem. I don't know why. When I used the first piece of code, without adding a URL, you can access it normally. This is strange.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.