2017-07-23 1 views
0

Je tente de me connecter à ews Exchange C via asp.net avec mon compte outlook sur le serveur d'échange et je reçois toujours "Lorsque vous faites une demande comme un compte qui n'a pas une boîte aux lettres, vous devez spécifier l'adresse SMTP principale de la boîte aux lettres pour tous les ID de dossier distingués. " lorsque je tente d'obtenir le calendrierse connecter à exchangeServices pour obtenir mon calendrier et obtenir une erreur

connexion à EWS:

private ExchangeService ConnectToService(ExchangeRetrivalParams exchangeRetrivalParams) 
{ 
    ExchangeService service = new ExchangeService(exchangeRetrivalParams.ExchangeVer); 
    service.Credentials = new WebCredentials(exchangeRetrivalParams.Username, exchangeRetrivalParams.Password); 
    service.UseDefaultCredentials = true; 
    service.AutodiscoverUrl(exchangeRetrivalParams.Email, RedirectionUrlValidationCallback); 
    return service; 
} 

essayant d'obtenir le calendrier:

try { 
    ExchangeService service = ConnectToService(email, username, password); 

    int NUM_APPTS = NumberOfItems; 

    // Initialize the calendar folder object with only the folder ID. 
    CalendarFolder calendar = CalendarFolder.Bind(service, WellKnownFolderName.Calendar, new PropertySet()); 
    //get the start and end times 
    DateTime startDate = new DateTime(2017, 7, 21); 
    DateTime endDate = new DateTime(2017, 7, 23); 

    // Set the start and end time and number of appointments to retrieve. 
    CalendarView cView = new CalendarView(startDate, endDate, NUM_APPTS); 
    // Limit the properties returned to the appointment's subject, start time, and end time. 
    cView.PropertySet = new PropertySet(AppointmentSchema.Start, 
             AppointmentSchema.End, 
             AppointmentSchema.IsRecurring, 
             AppointmentSchema.AppointmentType); 
} 
catch (Exception e) { 
    lastOperationErrorMsg = e.Message; 
    return null; 
} 

il échoue avec:

When making a request as an account that does not have a mailbox, you must specify the mailbox primary SMTP address for any distinguished folder Ids.

sur: CalendarFolder calendar = CalendarFolder.Bind(service, WellKnownFolderName.Calendar, new PropertySet());

toute aide serait appréciée.

Répondre

0

ok donc je l'ai trouvé travailler avec:

ExchangeService service = new ExchangeService("ExchangeVersion"); 
service.Credentials = new WebCredentials("Username", "Password", "Domain"); 
service.AutodiscoverUrl("Email", RedirectionUrlValidationCallback); 

et maintenant il ne se connecte une d récupérer tous les rendez-vous (en fonction des dates de début et de fin) demandés.

espère que c'est une bonne pratique et ouvert à de nouvelles suggestions

0

Votre utilisant à la fois webcredentials et UseDefaultCredentials par exemple

service.Credentials = new WebCredentials(exchangeRetrivalParams.Username, exchangeRetrivalParams.Password); 
service.UseDefaultCredentials = true; 

Vous devriez être utiliser l'une ou l'autre, si vous essayez de faire passer l'utilisateur actuellement connecté, vous devez traiter avec la délégation Kerbros par exemple, je suggère vous suivez l'exemple https://blogs.msdn.microsoft.com/emeamsgdev/2012/11/05/ews-from-a-web-application-using-windows-authentication-and-impersonation/

+0

si je supprimer un de ces: service.Credentials = new WebCredentials (exchangeRetrivalParams.Username, exchangeRetrivalParams.Password); service.UseDefaultCredentials = true; alors je reçois une erreur: "Le service Autodiscover n'a pas pu être localisé." – aura