Sdílet prostřednictvím


Navigating the Autodiscover Sample Application Source Code

The Autodiscover.cs file contains the logic to perform the Autodiscover query to obtain a client's configuration information. The AutodiscoverSample.cs file contains the user interface to the Autodiscover application. These files are installed in the directory in which the Exchange Server 2010 Software Development Kit (SDK) is installed, in the \Samples\Autodiscover\ folder.

The Autodiscover.cs and AutodiscoverSample.cs files are part of the Autodiscover sample that is included in the Microsoft Exchange Server 2010 SP2 Web Services SDK.

Note

This sample application is intended for instructional purposes and is not meant to be installed in a production environment.

Autodiscover Sample Application

This section describes the methods that are contained in the Autodiscover.cs and AutodiscoverSample.cs files.

Autodiscover.cs Methods

The following table lists and describes the methods of the Autodiscover class.

Autodiscover class methods

Method

Description

GetScpUrlList(string domainName, string ldapPath, ref int maxHops)

Tries to find the Autodiscover URL by searching through Service Connection Point (SCP) objects that are found in Active Directory.

Discover(string emailAddress, System.Net.NetworkCredential nc, ref int maxHops, bool allowSelfSignedCerts)

Gets the Autodiscover response.

DiscoverTryUrls(string emailAddress, System.Net.NetworkCredential nc, ref int maxHops, System.Collections.Generic.List<string> urls, bool authoritative, bool allowSelfSignedCerts)

Tries to get the Autodiscover response by using a set of URLs. The URLs are either default URLs or URLs that are defined by the SCP objects.

DiscoverTryUrl(string emailAddress, System.Net.NetworkCredential nc, string url, bool authoritative, bool allowSelfSignedCerts)

Tries to get the Autodiscover response by using a single URL.

GetRedirectUrl(string domainName)

Tries to get a SSL redirect URL to the Autodiscover service from a non-SSL URL.

CertificateValidationCallBack(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors)

Determines whether a certificate is valid.

Contains(System.Collections.ICollection collection, string match)

Identifies a string in a collection.

CheckAndDecrementHops(ref int maxHops)

Decrements a counter that limits the number of attempts to get the Autodiscover information.

IsOutlookDataReturned(AutodiscoverResponseXml autodiscoverResponse)

Looks for valid response data.

IsErrorResponseReturned(AutodiscoverResponseXml autodiscoverResponse)

Determines whether an error response is returned.

ConsoleTrace(string message)

Outputs messages to the console.

SerializeRequest(string emailAddress, System.IO.Stream requestStream)

Generates an Autodiscover request.

DeserializeResponse(System.IO.Stream responseStream)

Returns the Autodiscover response.

GetSiteName()

Gets the site name of the local computer.

This sample also contains samples that are sent to the Autodiscover service and the response that is returned from the service.

AutodiscoverSample.cs Methods

The AutodiscoverSample.cs file contains the console interface to the Autodiscover sample application. The following table lists and describes the methods of the AutodiscoverSample class.

AutodiscoverSample class methods

Method

Description

Main(string[] args)

Identifies the main entry point to the sample application.

WriteValue(string name, object value)

Writes a property value to the console.

WriteXmlNode(string prefix, System.Xml.XmlNode xmlNode)

Writes an XML element to the console.

WriteResponse(Autodiscover.AutodiscoverResponseXml response)

Writes the XML response to the console.

WriteHelp()

Writes help to the console window.