Getting User Availability

Use Exchange Web Services to access a user's free/busy information.

The following example shows you how to get the merged free/busy stream for a client in the Coordinated Universal Time -08:00 time zone by using updated information for the time zone changes that are made for daylight saving time.

static void GetUserAvailability(ExchangeServiceBinding esb)
    // Identify the time to compare free/busy information.
    Duration duration = new Duration();
    duration.StartTime = DateTime.Now;
    duration.EndTime = DateTime.Now.AddHours(4);

    // Identify the options for comparing free/busy information.
    FreeBusyViewOptionsType fbViewOptions = new FreeBusyViewOptionsType();
    fbViewOptions.TimeWindow = duration;
    fbViewOptions.RequestedView = FreeBusyViewType.MergedOnly;
    fbViewOptions.RequestedViewSpecified = true;
    fbViewOptions.MergedFreeBusyIntervalInMinutes = 35;
    fbViewOptions.MergedFreeBusyIntervalInMinutesSpecified = true;

    MailboxData[] mailboxes = new MailboxData[1];
    mailboxes[0] = new MailboxData();

    // Identify the user mailbox to review for free/busy data.
    EmailAddress emailAddress = new EmailAddress();

    emailAddress.Address = "";
    emailAddress.Name = String.Empty;

    mailboxes[0].Email = emailAddress;
    mailboxes[0].ExcludeConflicts = false;

    // Make the request.
    GetUserAvailabilityRequestType request = new GetUserAvailabilityRequestType();

    // Set the time zone of the request.
    request.TimeZone = new SerializableTimeZone();
    request.TimeZone.Bias = 480;
    request.TimeZone.StandardTime = new SerializableTimeZoneTime();
    request.TimeZone.StandardTime.Bias = 0;
    request.TimeZone.StandardTime.DayOfWeek = DayOfWeekType.Sunday.ToString();
    request.TimeZone.StandardTime.DayOrder = 1;
    request.TimeZone.StandardTime.Month = 11;
    request.TimeZone.StandardTime.Time = "02:00:00";
    request.TimeZone.DaylightTime = new SerializableTimeZoneTime();
    request.TimeZone.DaylightTime.Bias = -60;
    request.TimeZone.DaylightTime.DayOfWeek = DayOfWeekType.Sunday.ToString();
    request.TimeZone.DaylightTime.DayOrder = 2;
    request.TimeZone.DaylightTime.Month = 3;
    request.TimeZone.DaylightTime.Time = "02:00:00";

    // Add the mailboxes to the request.
    request.MailboxDataArray = mailboxes;

    // Add the view options to the request.
    request.FreeBusyViewOptions = fbViewOptions;

        // Send the request and get the response.
        GetUserAvailabilityResponseType response = esb.GetUserAvailability(request);

        // Access free/busy information.
        if (response.FreeBusyResponseArray.Length < 1)
            throw new Exception("No free/busy response data available.");
            foreach (FreeBusyResponseType fbrt in response.FreeBusyResponseArray)
                if (fbrt.ResponseMessage.ResponseClass == ResponseClassType.Error)
                    Console.WriteLine(string.Format("Error: {0}", fbrt.ResponseMessage.MessageText));
                    // Show the free/busy stream.
                    FreeBusyView fbv = fbrt.FreeBusyView;
                    Console.WriteLine(string.Format("Merged free/busy data: {0}", fbv.MergedFreeBusy));
    catch (Exception e)
        // Perform error processing.

The following XML example shows the XML request message that is sent from the client to the server.

<GetUserAvailabilityRequest xmlns:xsi="" 
  <TimeZone xmlns="">
  <MailboxDataArray xmlns="">
    <MailboxData xmlns="">
        <Name />
  <FreeBusyViewOptions xmlns="">

The following XML example shows the XML response message that is sent from the server to the client.

<GetUserAvailabilityResponse xmlns:xsi="" 
  <FreeBusyResponseArray xmlns="">
      <ResponseMessage ResponseClass="Success">
        <FreeBusyViewType xmlns="">MergedOnly</FreeBusyViewType>
        <MergedFreeBusy xmlns="">0000000</MergedFreeBusy>
        <WorkingHours xmlns="">
              <DayOfWeek>Monday Tuesday Wednesday Thursday Friday</DayOfWeek>

The SOAP messages that are passed between the Exchange Web Services client and server are defined by the XML schema and WSDL files. The XML schema and WSDL files define the contract between the client and server. Proxy class generators create an object-model abstraction of those SOAP messages, which can simplify programming. This code example uses a proxy class library that was generated by MicrosoftVisual Studio 2005. Different proxy class generators create different object models for a given Web service. This proxy class code example is an illustration only. Refer to the proxy class generator documentation for support for proxy classes.

© 2014 Microsoft