More .NET libraries
-
Rebex Mail Pack
IMAP, MS Graph, EWS, POP3, SMTP, MIME, S/MIME, MSG
-
Rebex Total Pack
All Rebex .NET libraries together
Back to feature list...
Connecting
On this page:
Connecting to servers using EWS protocol
To connect to Exchange web services running on default port (443), call the single-parameter Connect
method.
A secured (encrypted) HTTPS connection is established.
// create EWS client instance
var client = new Rebex.Net.Ews();
// connect to a server using HTTPS protocol
// - implicit TLS/SSL mode
client.Connect(hostname);
' create EWS client instance
Dim client = New Rebex.Net.Ews()
' connect to a server using HTTPS protocol
' - implicit TLS/SSL mode
client.Connect(hostname)
Connect
method as an additional argument.
Tip: For advanced security options, see TLS/SSL core section.
Connecting to servers over unsecure HTTP protocol
To establish unsecure (HTTP) connection to Exchange server, use the Connect
method with SslMode.None
argument.
Please note that EWS does not support explicit TLS/SSL (use SslMode.Implicit
instead).
Tip: Learn about the difference between explicit and implicit TLS/SSL modes.
// create EWS client instance
var client = new Rebex.Net.Ews();
// connect to a server using HTTP protocol
// - no TLS/SSL mode
client.Connect(hostname, SslMode.None);
' create EWS client instance
Dim client = New Rebex.Net.Ews()
' connect to a server using HTTP protocol
' - no TLS/SSL mode
client.Connect(hostname, SslMode.None)
Server certificate is validated automatically by Rebex EWS, but you can customize the validation process as well.
Note: For Rebex.Net.Ews
, if port number is not specified, the 80 is used as a default port number for SslMode.None
(HTTP protocol).
Getting info about the connection
Once connected (or authenticated), you can get useful information about the current connection such as server name, server port or user name. Don't be afraid - user's password is not stored with the connection.
// create client instance
var client = new Rebex.Net.Ews();
// connect to a server
client.Connect(hostname);
// display info
Console.WriteLine("Connected to {0}:{1}.", client.ServerName, client.ServerPort);
// authenticate
client.Login(username, password);
// display info to the user
Console.WriteLine("Logged on as {0}.", client.UserName);
' create client instance
Dim client = New Rebex.Net.Ews()
' connect to a server
client.Connect(hostname)
' display info
Console.WriteLine("Connected to {0}:{1}.", client.ServerName, client.ServerPort)
' authenticate
client.Login(username, password)
' display info to the user
Console.WriteLine("Logged on as {0}.", client.UserName)
Getting info about TLS/SSL connection
To get information about SSL connection, use TlsSocket
property.
// create client instance
var client = new Rebex.Net.Ews();
// connect to a server
client.Connect(hostname);
// Cipher property contains a lot of information about the current cipher
Console.WriteLine("TLS cipher info: {0}", client.TlsSocket.Cipher);
// ServerCertificate property provides access to server certificate
// the first certificate in the chain is the server's certificate
CertificateChain chain = client.TlsSocket.ServerCertificate;
Console.WriteLine("Server's certificate info: Subject: {0}, Issuer: {1}",
chain[0].GetSubject(), chain[0].GetIssuer());
' create EWS client instance
Dim client = New Rebex.Net.Ews()
' connect to a server
client.Connect(hostname, SslMode.Explicit)
' Cipher property contains a lot of information about the current cipher
Console.WriteLine("TLS cipher info: {0}", client.TlsSocket.Cipher)
' ServerCertificate property provides access to server certificate
' the first certificate in the chain is the server's certificate
Dim chain As CertificateChain = client.TlsSocket.ServerCertificate
Console.WriteLine("Server's certificate info: Subject: {0}, Issuer: {1}",
chain(0).GetSubject(), chain(0).GetIssuer())
Back to feature list...