Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

CHAPTER 12: Developing Exchange Online S... > Connecting to Exchange with Autodisc...

Connecting to Exchange with Autodiscover

Now you're ready to implement the four functions I listed at the beginning of the chapter:

  • Connecting to the Exchange Online server
  • Accessing mailbox items
  • Determining availability
  • Subscribing to notifications

Before you can do anything else, you'll need to connect to the Exchange server. I'll start with that feature. You will first add the logic in the ExchangeDataContext class that calls the autodiscover process. Then you'll implement the click event in the code-behind class.

Implementing the ExchangeDataContext Class

Go to the ExchangeDataContext class and add the code shown in Listing 12-1 to the class definition.

Listing 12-1. Connecting to the Exchange Server

private ExchangeService _service;

public ExchangeDataContext(string emailAddress, string password)
    _service = GetBinding(emailAddress, password);

public ExchangeService GetService()
    return _service;

static ExchangeService GetBinding(string emailAddress, string password)
    // Create the binding.
    ExchangeService service =
        new ExchangeService(ExchangeVersion.Exchange2010_SP1);

    // Define credentials.
    service.Credentials = new WebCredentials(emailAddress, password);

    // Use the AutodiscoverUrl method to locate the service endpoint.
        service.AutodiscoverUrl(emailAddress, RedirectionUrlValidationCallback);


You are currently reading a PREVIEW of this book.


Get instant access to over $1 million worth of books and videos.


Start a Free 10-Day Trial

  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint