Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
Exchange Web Services .NET
>
Tutorial
> Resolve names
The following example shows you how to resolve contacts.
C# example
using System; using System.Net; using Independentsoft.Exchange; namespace Sample { class Program { static void Main(string[] args) { NetworkCredential credential = new NetworkCredential("username", "password"); Service service = new Service("https://myserver/ews/Exchange.asmx", credential); try { ResolveNamesResponse response = service.ResolveNames("John"); for (int i = 0; i < response.Resolutions.Count; i++) { Resolution resolution = response.Resolutions[i]; if (resolution != null && resolution.Mailbox != null) { Mailbox mailbox = resolution.Mailbox; Console.WriteLine("Name = " + mailbox.Name); Console.WriteLine("EmailAddress = " + mailbox.EmailAddress); } if (resolution != null && resolution.Contact != null) { Contact contact = resolution.Contact; Console.WriteLine("GivenName = " + contact.GivenName); Console.WriteLine("EmailAddress = " + contact.Email1Address); } } Console.Read(); } catch (ServiceRequestException ex) { Console.WriteLine("Error: " + ex.Message); Console.WriteLine("Error: " + ex.XmlMessage); Console.Read(); } catch (WebException ex) { Console.WriteLine("Error: " + ex.Message); Console.Read(); } } } }
VB example
Imports System Imports System.Net Imports Independentsoft.Exchange Namespace Sample Class Module1 Shared Sub Main(ByVal args As String()) Dim credential As New NetworkCredential("username", "password") Dim service As New Service("https://myserver/ews/Exchange.asmx", credential) Try Dim response As ResolveNamesResponse = service.ResolveNames("John") For i As Integer = 0 To response.Resolutions.Count - 1 Dim resolution As Resolution = response.Resolutions(i) If resolution IsNot Nothing AndAlso resolution.Mailbox IsNot Nothing Then Dim mailbox As Mailbox = resolution.Mailbox Console.WriteLine("Name = " & mailbox.Name) Console.WriteLine("EmailAddress = " & mailbox.EmailAddress) End If If resolution IsNot Nothing AndAlso resolution.Contact IsNot Nothing Then Dim contact As Contact = resolution.Contact Console.WriteLine("GivenName = " & contact.GivenName) Console.WriteLine("EmailAddress = " & contact.Email1Address) End If Next Console.Read() Catch ex As ServiceRequestException Console.WriteLine("Error: " + ex.Message) Console.WriteLine("Error: " + ex.XmlMessage) Console.Read() Catch ex As WebException Console.WriteLine("Error: " + ex.Message) Console.Read() End Try End Sub End Class End Namespace
Need help? Ask our developers:
Name*
Email*
Message*