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.