EWS Autodiscover not working, cycle through calendar items

I'm trying to create a program that cycles through all user calendars and records their calendar items.  However, I can't seem to do anything other than access my calendar.  I'm the Systems Administrator and have access to all admin accounts and admin network credentials.

How can I get a user's (other than mine) calendar items?  I get autodiscover errors so I am putting in the service URL directly.

Thanks,
JOe K.


//THIS WORKS

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);

service.UseDefaultCredentials = true;
service.Url = new Uri ("https://mydomain/EWS/Exchange.asmx");
                
                Appointment appointment = new Appointment(service);
                appointment.Subject = "Dentist Appointment";
                appointment.Body = "The appointment is with Dr. Smith.";
                appointment.Start = new DateTime(2012, 1, 3, 9, 0, 0);
                appointment.End = appointment.Start.AddHours(2);
                appointment.Save(SendInvitationsMode.SendToNone);

Open in new window

ClaudeWalkerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Luis PérezSoftware Architect in .NetCommented:
To access another user's calendar items (or emails, or anything else), you must "say" to EWS that you want to impersonate that user.

service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "myuser@mydomain.com")

You can use the mail e-mail address of the user to impersonate, as well as other data like the Principal name or the SID.

In the other hand, try this to get working your Autodiscover service:

using System.Security.Cryptography.X509Certificates;
using System.Net.Security;

public static bool OnValidationCallback(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors errors)
{
      return true;
}

And, before calling Autodiscover:
ServicePointManager.ServerCertificateValidationCallback == new RemoteCertificateValidationCallback(OnValidationCallback);

This function is to bypass the certificate validation that EWS requires.

Hope that helps.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ClaudeWalkerAuthor Commented:
That definitely helps.  Now I need to Enable Impersonation on the account:

Per the documentation to enable it for all users:

New-ManagementRoleAssignment –Name:impersonationAssignmentName –Role:ApplicationImpersonation –User:serviceAccount

However, I don't know what the parameters are supposed to me :

impersonationAssignmentName (is this just an arbitrary named thing, could I keep it the same
ApplicationImpersonation (Is this meant to be as is)
serviceAccount (is this an email account, sharedTest@mydomain.com)

I'm close...

Thanks,
JOe K.
0
Luis PérezSoftware Architect in .NetCommented:
You must left all the data as the way you wrote it except for "serviceAccount" that must be your account (your user name into the domain, the one which you log in with).

Hope that helps.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

ClaudeWalkerAuthor Commented:
I'm still getting the same error even after adding that to EMS.

Here is my code:

Here is what I used to enable impersonation:  New-ManagementRoleAssignment –Name:impersonationAssignmentName –Role:ApplicationImpersonation –User:userLogin

 
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
                    service.Url = new Uri("https://myDomain.com/EWS/Exchange.asmx");
           
                    service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "userLogin@myDomain.com");
                    
                    Folder folder = Folder.Bind(service, WellKnownFolderName.Calendar);
                               
                    Console.WriteLine(folder.DisplayName);

Open in new window

0
ClaudeWalkerAuthor Commented:
Sorry about the tabbing in the embedded code.
0
ClaudeWalkerAuthor Commented:
Nevermind, this was the issue:  Console.WriteLine(folder.DisplayName);

I can get Console.WriteLine(folder.Id); to work instead meaning its connecting.
0
ClaudeWalkerAuthor Commented:
Now I have access to the calendar folder for all users

how can I grab the calendar items using folder.???
0
Luis PérezSoftware Architect in .NetCommented:
Does Console.WriteLine(folder.Id) works?
0
ClaudeWalkerAuthor Commented:
Yes.  I got it!

foreach (Item item in calendar.FindItems(new ItemView(100)))
{
     Console.WriteLine(item.Subject);
}


I was able to cycle through all of the items in a calendar.  Now I can put some date conditions in and loop through a number of email addresses.

Perfect!

Thank you soooo much!

JOe K.
0
Luis PérezSoftware Architect in .NetCommented:
Glad to help you!!

Greetings and happy new year!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.