EWS The request failed. The remote server returned an error: (401) Unauthorized RRS feed

  • Question

  • Hello,

    I am trying to create appointment from Exchange Web Service, If I am trying to login to exchange server from URL then its working and allowing me to login to my exchange server but if I am trying to connect from my C# application then I am getting this error "The request failed. The remote server returned an error: (401) Unauthorized."

    My current code is as below:

    ExchangeService service = new ExchangeService();
    service.Credentials = new WebCredentials("XXX\username", "pwd", "");
    service.Url = new Uri(""); 
    Appointment appointment = new Appointment(service);
    appointment.Subject = "Status Meeting";
    appointment.Body = "The purpose of this meeting is to discuss status.";
    appointment.Start = new DateTime(2017, 1, 30, 9, 0, 0);
    appointment.End = appointment.Start.AddHours(2);
    appointment.Location = "Conf Room";

    If I am trying to login from url and its also working fine.
    username - XXX\username
    pwd - "pwd"

    Also I have tried to login web service from URL and its work for me.

    Please anyone suggest what's the wrong with C# code and how I can make working it.


    Monday, January 30, 2017 8:49 AM


All replies

  • You credentials aren't specified correctly you should use either downlevel format which is domain\username which would be

    service.Credentials = new WebCredentials("XXX\username", "pwd");

    (Note you don't specify the domain as you have already included it in the downlevel format)

    or use

    service.Credentials = new WebCredentials("username", "pwd","XXX");

    (Where XXX is the NetBIOS domain name not the FQDN like you have used) this is recommended method because of potential issue with UPN suffixes

    or use the Active Directory User Principal name which includes the domain name eg

    service.Credentials = new WebCredentials("", "pwd");


    • Marked as answer by NH Kariya Tuesday, January 31, 2017 5:49 PM
    Tuesday, January 31, 2017 3:43 AM
  • Hello Glen,

    Thank you so much. Its working for me.

    service.Credentials = new WebCredentials("username", "pwd","XXX")


    NH Kariya

    Tuesday, January 31, 2017 5:51 PM