locked
EWS Authentication RRS feed

  • Question

  • Hi,

    My application is utilizing the Exchange EWS services to extract calendar events. For some customers it works fine, but for other not so much. The ones that do seem to have NTML auth enabled, and I get a log-on popup when browsing the wsdl. The ones that don't work has basic auth, and I'm redirected to a Forefront login page.

    So my question is; Using the EWS api, how can I authenticate to a server using Forefront?

    This is what my code look like to day:

            internal ExchangeServiceBinding GetExchangeBinding(ExchangeCredential credentials)
            {
                ExchangeServiceBinding binding = new ExchangeServiceBinding();
                ServicePointManager.ServerCertificateValidationCallback =
                        delegate(Object obj, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
                        {
                            // Replace this line with code to validate server certificate.
                            return true;
                        };
    
                System.Net.WebProxy proxyObject = new System.Net.WebProxy();
                proxyObject.Credentials = System.Net.CredentialCache.DefaultCredentials;
    
                binding.Credentials = new NetworkCredential(credentials.UserName, credentials.Password, credentials.Domain);
                binding.Url = credentials.Uri;// @"https://someservice.com/EWS/Exchange.asmx";
    
                binding.Proxy = proxyObject;
    
                return binding;
            }
    

     

    If this answers your question, please use the "Answer" button to say so... Mikael - http://blogical.se/blogs/mikael

    Friday, October 26, 2012 12:19 PM

Answers

  • There is nothing in the Managed API to deal with a Forefront FBA login but you shouldn't really be seeing this if TMG rule for EWS is setup properly. Do other EWS clients work eg (Outlook Mac 2011, https://www.testexchangeconnectivity.com/ etc)

    The Managed API should be able to negotiate the correct authentication but in the case this is failing you can just tell it to only use Basic eg

                ExchangeService service = new ExchangeService();
                service.Url = new Uri("https://sn2prd0310.outlook.com/EWS/Exchange.asmx");
                NetworkCredential ncCred = new NetworkCredential("user@domain.com", "pass");
                CredentialCache cCache = new CredentialCache();
                cCache.Add(service.Url, "Basic", ncCred);
                service.TraceEnabled = true;
                service.Credentials = cCache;
                Folder Inbox = Folder.Bind(service, WellKnownFolderName.Inbox);

    (*Note you should be using Autodiscover to the EWS URL)

    Cheers
    Glen

    Monday, October 29, 2012 3:48 AM