EWS Appointment 401 unauthorized error on Echange 2010 RRS feed

  • Question

  • Hi,

    I'm trying to use EWS to create an Appointment and save to user's outlook calendar, when calling EWS service, I can get passed for server.AutodiscoverUrl, but when I try to save the Appointment, I got "401 unauthorized" error returned, anybody can help me out? the EWS URL is correct since i got from Exchange online under my account.

    Here is my code:

    ServicePointManager.ServerCertificateValidationCallback = CertificateValidationCallBack;

    ServicePointManager.ServerCertificateValidationCallback = CertificateValidationCallBack;

    ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);

    service.TraceEnabled =


    service.TraceFlags =


    service.Url =

    new Uri("https://XXXDomain/EWS/Exchange.asmx");


    "", RedirectionUrlValidationCallback2);

    Appointment appointment = new Appointment(service);

    appointment.Subject =


    appointment.Start =


    appointment.End = appointment.Start.AddHours(1);





    Any help is great appreicated.


    Wednesday, November 7, 2012 5:55 PM

All replies

  • You are not specifying any credentials to use you should either specify to use the Default Credentials if you want to use the currently logged on credentials or specify a specific set of credentials have a read of which details both methods.


    Thursday, November 8, 2012 5:07 AM
  • Hi Glen:

    Thank you very much for the reply, sorry I missed to post the line setting up the credentials, I did set the credential as

    service.Credentials =

    new WebCredentials("myemail", "password", "mydomain");I also tried set

    service.UseDefaultCredentials =

    true;but still got same 401 unauthorized error returned, do I need some setting to the email account which will send out the meeting in the outlook?
    Thursday, November 8, 2012 4:25 PM
  • Hi Glen:

    I found I had domain name set for the credential which is not needed when using email and password, after I remove the domain name, it's working :)


    Thursday, November 8, 2012 7:28 PM