exchangewebservices - Using EWS with Office 365 fails with Server doesn't support requested version -


using windows 8 (64 bit) , visual studio 2012 ultimate, update 2.

i trying use exchange web services 2.0 (ews) office 365. getting following exception occurs on call findresults (last line in main):

microsoft.exchange.webservices.data.serviceversionexception unhandled   hresult=-2146233088   message=exchange server doesn't support requested version.   source=microsoft.exchange.webservices   stacktrace:        @ microsoft.exchange.webservices.data.servicerequestbase.processwebexception(webexception webexception)        @ microsoft.exchange.webservices.data.servicerequestbase.getewshttpwebresponse(iewshttpwebrequest request)        @ microsoft.exchange.webservices.data.servicerequestbase.validateandemitrequest(iewshttpwebrequest& request)        @ microsoft.exchange.webservices.data.simpleservicerequestbase.internalexecute()        @ microsoft.exchange.webservices.data.multiresponseservicerequest`1.execute()        @ microsoft.exchange.webservices.data.exchangeservice.finditems[titem](ienumerable`1 parentfolderids, searchfilter searchfilter, string querystring, viewbase view, grouping groupby, serviceerrorhandling errorhandlingmode)        @ microsoft.exchange.webservices.data.exchangeservice.finditems(folderid parentfolderid, searchfilter searchfilter, viewbase view)        @ microsoft.exchange.webservices.data.exchangeservice.finditems(wellknownfoldername parentfoldername, viewbase view)        @ test_ews.program.main(string[] args) in c:\users\john.tarbox\documents\visual studio 2012\projects\test_ews\test_ews\program.cs:line 85        @ system.appdomain._nexecuteassembly(runtimeassembly assembly, string[] args)        @ system.appdomain.executeassembly(string assemblyfile, evidence assemblysecurity, string[] args)        @ microsoft.visualstudio.hostingprocess.hostproc.runusersassembly()        @ system.threading.threadhelper.threadstart_context(object state)        @ system.threading.executioncontext.runinternal(executioncontext executioncontext, contextcallback callback, object state, boolean preservesyncctx)        @ system.threading.executioncontext.run(executioncontext executioncontext, contextcallback callback, object state, boolean preservesyncctx)        @ system.threading.executioncontext.run(executioncontext executioncontext, contextcallback callback, object state)        @ system.threading.threadhelper.threadstart()   innerexception:  

here code sample:

using microsoft.exchange.webservices.autodiscover; using microsoft.exchange.webservices.data; using system; using system.net;   namespace test_ews {     class program     {         private static bool certificatevalidationcallback(             object sender,             system.security.cryptography.x509certificates.x509certificate certificate,             system.security.cryptography.x509certificates.x509chain chain,             system.net.security.sslpolicyerrors sslpolicyerrors)         {             // if certificate valid, signed certificate, return true.             if (sslpolicyerrors == system.net.security.sslpolicyerrors.none)             {                 return true;             }              // if there errors in certificate chain, @ each error determine cause.             if ((sslpolicyerrors & system.net.security.sslpolicyerrors.remotecertificatechainerrors) != 0)             {                 if (chain != null && chain.chainstatus != null)                 {                     foreach (system.security.cryptography.x509certificates.x509chainstatus status in chain.chainstatus)                     {                         if ((certificate.subject == certificate.issuer) &&                            (status.status == system.security.cryptography.x509certificates.x509chainstatusflags.untrustedroot))                         {                             // self-signed certificates untrusted root valid.                              continue;                         }                         else                         {                             if (status.status != system.security.cryptography.x509certificates.x509chainstatusflags.noerror)                             {                                 // if there other errors in certificate chain, certificate invalid,                                 // method returns false.                                 return false;                             }                         }                     }                 }                  // when processing reaches line, errors in certificate chain                  // untrusted root errors self-signed certificates. these certificates valid                 // default exchange server installations, return true.                 return true;             }             else             {                 // in other cases, return false.                 return false;             }         }           static void main(string[] args)         {             servicepointmanager.servercertificatevalidationcallback = certificatevalidationcallback;             exchangeservice service = new exchangeservice();             service.credentials = new webcredentials("xxx@yyy.com", "password");              service.traceenabled = true;             service.traceflags = traceflags.all;              try             {                 service.autodiscoverurl("xxx@yyy.com", redirectionurlvalidationcallback);             }             catch (autodiscoverremoteexception ex)             {                                 console.writeline("exception thrown: " + ex.error.message);           }              finditemsresults<item> findresults = service.finditems(                                        wellknownfoldername.inbox,                                        new itemview(10));         }          private static bool redirectionurlvalidationcallback(string redirectionurl)         {            // default validation callback reject url.            bool result = false;             uri redirectionuri = new uri(redirectionurl);             // validate contents of redirection url. in simple validation            // callback, redirection url considered valid if using https            // encrypt authentication credentials.             if (redirectionuri.scheme == "https")            {               result = true;            }            return result; }      } } 

if change line:

exchangeservice service = new exchangeservice(); 

to

exchangeservice service = new exchangeservice(exchangeversion.exchange2007_sp1); 

the code works fine. not understand why 1 should need pass version explicitly on call; why fail without specific version?


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -