none
Ews Exchange Issue RRS feed

  • Question

  • I have added Service reference to the following URL in Visual Studio.Net 

    https://outlook.office365.com/ews/services.wsdl

    Service is created in reference. I need a sample code to fetch all Appointments of today's date. I tried the following Code but not working.

    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using Microsoft.Exchange.WebServices.Data;
    using InfoPointCsharp.ExchangeServiceUAEU;
    namespace InfoPointCsharp
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }

            private static bool RedirectionUrlValidationCallback(string redirectionUrl)
            {
                // The default for the validation callback is to reject the URL.
                bool result = false;

                Uri redirectionUri = new Uri(redirectionUrl);

                // Validate the contents of the redirection URL. In this simple validation
                // callback, the redirection URL is considered valid if it is using HTTPS
                // to encrypt the authentication credentials. 
                if (redirectionUri.Scheme == "https")
                {
                    result = true;
                }
                return result;
            }

            private void Form1_Load(object sender, EventArgs e)
            {
                
                ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
                service.Credentials = new WebCredentials("abc@domain", "*******", "DomainName");
                service.UseDefaultCredentials = true;
                service.AutodiscoverUrl("infopointexch@uaeu.ac.ae", RedirectionUrlValidationCallback);

                service.Url = new Uri("https://outlook.office365.com/ews/exchange.asmx");
                MessageBox.Show(service.Url.ToString());
                Console.WriteLine("EWS Endpoint: {0}", service.Url);
                /*
                CalendarFolder cf = new CalendarFolder(service);

                DateTime startDate = DateTime.Now;
                DateTime endDate = startDate.AddDays(30);
                const int NUM_APPTS = 15;
                // Set the start and end time and number of appointments to retrieve.
                CalendarView cView = new CalendarView(startDate, endDate, NUM_APPTS);
               

                FindItemsResults<Appointment> appointments = cf.FindAppointments(cView);
                foreach (Appointment a in appointments)
                {
                    Console.Write("Subject: " + a.Subject.ToString() + " ");
                    Console.Write("Start: " + a.Start.ToString() + " ");
                    Console.Write("End: " + a.End.ToString());
                    Console.WriteLine();
                }
                */


                /*
                var folderView = new FolderView(100);   // or something like 100, idunno
                folderView.Traversal = FolderTraversal.Deep;
                folderView.PropertySet = new PropertySet(FolderSchema.FolderClass, FolderSchema.DisplayName, FolderSchema.TotalCount, FolderSchema.ParentFolderId);   // ... and/or whatever else you want to get - folderclass is important though. 

                FindFoldersResults folders = service.FindFolders(WellKnownFolderName.MsgFolderRoot, folderView);
                // Process each item.
                foreach (Folder myFolder in folders.Folders)
                {
                    if (myFolder is CalendarFolder)
                    {
                        var calendar = (myFolder as CalendarFolder);
                        // Initialize values for the start and end times, and the number of appointments to retrieve.
                        DateTime startDate = DateTime.Now;
                        DateTime endDate = startDate.AddDays(30);
                        const int NUM_APPTS = 15;
                        // 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.Subject, AppointmentSchema.Start, AppointmentSchema.End);
                        // Retrieve a collection of appointments by using the calendar view.
                        FindItemsResults<Appointment> appointments = calendar.FindAppointments(cView);
                        foreach (Appointment a in appointments)
                        {
                            Console.Write("Subject: " + a.Subject.ToString() + " ");
                            Console.Write("Start: " + a.Start.ToString() + " ");
                            Console.Write("End: " + a.End.ToString());
                            Console.WriteLine();
                        }
                    }

                }
                */
            }
        }
    }


    khalid

    Thursday, December 21, 2017 8:27 AM

All replies

  • You need to define what you mean by 'not working' eg give the errors that your are getting (try reading the forum guide if you not sure which is the first post in the list)

    for Office365 this would be wrong

                service.Credentials = new WebCredentials("abc@domain", "*******", "DomainName");
                service.UseDefaultCredentials = true;
                service.AutodiscoverUrl("infopointexch@uaeu.ac.ae", RedirectionUrlValidationCallback);

    You won't be able to use the Default credentials or downlevel logon format so just use

                service.Credentials = new WebCredentials("abc@domain", "*******");
                service.AutodiscoverUrl("infopointexch@uaeu.ac.ae", RedirectionUrlValidationCallback);


    BTW you don't need the service reference because you trying to use EWS managed API code which is a client library that does the SOAP request and parses the responses for you.

    Cheers
    Glen

    Friday, December 22, 2017 2:42 AM