I am trying to experiment using Exchange EWS 2 on debian via Mono (versions 2.10.8.1 and 3.0.6) I am developing Windows 8 using vs2012.
The program works fine on windows, and I get the expected result.
In mono, however, I continue to get the following output and exception.
<Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2013-03-07 19:09:05Z">
Starting SCP lookup for domainName='example.com', root path=''
</Trace>
Connect Error
Unhandled Exception: LdapException: (91) Connect Error
System.Net.Sockets.SocketException: No such host is known
at System.Net.Dns.hostent_to_IPHostEntry (System.String h_name, System.String[] h_aliases, System.String[] h_addrlist) [0x00000] in <filename unknown>:0
at System.Net.Dns.GetHostByName (System.String hostName) [0x00000] in <filename unknown>:0
at System.Net.Dns.GetHostEntry (System.String hostNameOrAddress) [0x00000] in <filename unknown>:0
at System.Net.Dns.GetHostAddresses (System.String hostNameOrAddress) [0x00000] in <filename unknown>:0
at System.Net.Sockets.TcpClient.Connect (System.String hostname, Int32 port) [0x00000] in <filename unknown>:0
at System.Net.Sockets.TcpClient..ctor (System.String hostname, Int32 port) [0x00000] in <filename unknown>:0
at Novell.Directory.Ldap.Connection.connect (System.String host, Int32 port, Int32 semaphoreId) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: LdapException: (91) Connect Error
System.Net.Sockets.SocketException: No such host is known
at System.Net.Dns.hostent_to_IPHostEntry (System.String h_name, System.String[] h_aliases, System.String[] h_addrlist) [0x00000] in <filename unknown>:0
at System.Net.Dns.GetHostByName (System.String hostName) [0x00000] in <filename unknown>:0
at System.Net.Dns.GetHostEntry (System.String hostNameOrAddress) [0x00000] in <filename unknown>:0
at System.Net.Dns.GetHostAddresses (System.String hostNameOrAddress) [0x00000] in <filename unknown>:0
at System.Net.Sockets.TcpClient.Connect (System.String hostname, Int32 port) [0x00000] in <filename unknown>:0
at System.Net.Sockets.TcpClient..ctor (System.String hostname, Int32 port) [0x00000] in <filename unknown>:0
at Novell.Directory.Ldap.Connection.connect (System.String host, Int32 port, Int32 semaphoreId) [0x00000] in <filename unknown>:0
Apparently he is trying to find a host that he cannot find. Both my windows and Linux systems use the same DNS server, so this does not cause a problem.
I read the trace on the windows when it works - and the trace shows that the requests do not work several times, and the autodiscover method tries several different URLs until it hits one that works - mono, but it seems to crash after the first failure and the end.
Google ews , , , , .
-
http://msdn.microsoft.com/en-us/library/exchange/dd633709(v=exchg.80).aspx
class Program
{
private static int verbose = 10;
private static string loginEmail = "email@example.com";
private static string password = "#############";
static void Main(string[] args)
{
try
{
ServicePointManager.ServerCertificateValidationCallback = CertificateValidationCallBack;
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
service.Credentials = new WebCredentials(loginEmail, password);
if (verbose >= 10)
{
service.TraceEnabled = true;
service.TraceFlags = TraceFlags.All;
}
service.AutodiscoverUrl(loginEmail, RedirectionUrlValidationCallback);
Console.WriteLine("AutoDiscover Completed");
getContacts(service);
Console.ReadLine();
}
catch (Exception e) {
Console.WriteLine(e.Message);
foreach (string key in e.Data.Keys)
{
Console.WriteLine(String.Format("{0}: {1}",key, e.Data[key]));
}
throw e;
}
}
private static void getContacts(ExchangeService service){
ContactsFolder contactsfolder = ContactsFolder.Bind(service, WellKnownFolderName.Contacts);
int numItems = contactsfolder.TotalCount < 1000 ? contactsfolder.TotalCount : 1000;
ItemView view = new ItemView(numItems);
FindItemsResults<Item> contactItems = service.FindItems(WellKnownFolderName.Contacts, view);
foreach (Item item in contactItems)
{
if (item is Contact)
{
Contact contact = item as Contact;
Console.WriteLine();
Console.WriteLine(contact.DisplayName);
if (verbose >= 2)
{
Console.WriteLine(" " + contact.Id);
}
try
{
Console.WriteLine(" " + contact.EmailAddresses[EmailAddressKey.EmailAddress1].ToString());
}
catch (Exception e)
{
if (verbose >= 5)
{
Console.WriteLine(" " + "Email Address 1 Not Available : " + e.Message);
}
}
}
}
}
#region taken from tutorial
private static bool CertificateValidationCallBack(
object sender,
System.Security.Cryptography.X509Certificates.X509Certificate certificate,
System.Security.Cryptography.X509Certificates.X509Chain chain,
System.Net.Security.SslPolicyErrors sslPolicyErrors)
{
if (sslPolicyErrors == System.Net.Security.SslPolicyErrors.None)
{
return true;
}
if ((sslPolicyErrors & System.Net.Security.SslPolicyErrors.RemoteCertificateChainErrors) != 0)
{
if (chain != null && chain.ChainStatus != null)
{
foreach (System.Security.Cryptography.X509Certificates.X509ChainStatus status in chain.ChainStatus)
{
if ((certificate.Subject == certificate.Issuer) &&
(status.Status == System.Security.Cryptography.X509Certificates.X509ChainStatusFlags.UntrustedRoot))
{
continue;
}
else
{
if (status.Status != System.Security.Cryptography.X509Certificates.X509ChainStatusFlags.NoError)
{
return false;
}
}
}
}
return true;
}
else
{
return false;
}
}
private static bool RedirectionUrlValidationCallback(string redirectionUrl)
{
bool result = false;
Uri redirectionUri = new Uri(redirectionUrl);
if (redirectionUri.Scheme == "https")
{
result = true;
}
return result;
}
#endregion
}
BeepBeep .
BeepBeep , - Mono dnsapi.dll( ). , .
,
service.AutodiscoverUrl(loginEmail, RedirectionUrlValidationCallback);
service.Url = new Uri("https://blah.com/ews/exchange.asmx");
( - " " ). , , mono root ca , :
, mozroots. , , .
tlstest FAQ - ( , ). , FAQ (certmgr) .
.