none
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 =

    true;

    service.TraceFlags =

    TraceFlags.All;

    service.Url =

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

    service.AutodiscoverUrl(

    "myname@mydomain.com", RedirectionUrlValidationCallback2);

    Appointment appointment = new Appointment(service);

    appointment.Subject =

    "Testing";

    appointment.Start =

    DateTime.Now;

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

    appointment.RequiredAttendees.Add(

    "myname@mydomain.com");

    appointment.Save(

    SendInvitationsMode.SendOnlyToAll);

    Any help is great appreicated.

    Regards,

    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 http://msdn.microsoft.com/en-us/library/exchange/ff597939(v=exchg.80).aspx which details both methods.

    Cheers
    Glen

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

    Ping

    Thursday, November 8, 2012 7:28 PM