当前位置: 首页>>代码示例>>C#>>正文


C# ExchangeService.ConvertId方法代码示例

本文整理汇总了C#中ExchangeService.ConvertId方法的典型用法代码示例。如果您正苦于以下问题:C# ExchangeService.ConvertId方法的具体用法?C# ExchangeService.ConvertId怎么用?C# ExchangeService.ConvertId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ExchangeService的用法示例。


在下文中一共展示了ExchangeService.ConvertId方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Authenticate

        /// <summary>
        /// Authenticates using the credentials provided to the credential manager. It also 
        /// populates the ExchangeService object used by the application.
        /// </summary>
        /// <param name="userprincipalname">The user's name for accessing Exchange</param>
        /// <param name="password">The user's password.</param>
        /// <param name="service">The ExchangeService object for this application.</param>
        /// <returns>A value of true indicates that the client successfully authenticated with EWS.</returns>
        private static bool Authenticate(string userprincipalname, SecureString password, ref ExchangeService service)
        {
            bool authenticated = false;
            try
            {
                service.Credentials = new NetworkCredential(userprincipalname, password);

                // Check if we have the service URL.
                if (service.Url == null)
                {
                    Console.WriteLine("Wyszukiwanie EWS URL dla konta {0}. Czekaj... ", userprincipalname);
                    service.AutodiscoverUrl(userprincipalname, Service.RedirectionUrlValidationCallback);
                    Console.WriteLine("Wyszukiwanie zakończone.");
                }

                // Once we have the URL, try a ConvertId operation to check if we can access the service. We expect that
                // the user will be authenticated and that we will get an error code due to the invalid format. Expect a
                // ServiceResponseException.
                Console.WriteLine("Łączenie z EWS...");
                AlternateIdBase response = service.ConvertId(new AlternateId(IdFormat.EwsId, "Placeholder", userprincipalname), IdFormat.EwsId);
            }

            // The user principal name is in a bad format.
            catch (FormatException fe)
            {
                Console.WriteLine("Błąd: {0} Wprowadź dane dostępowe w formacie UPN.", fe.Message);
                //service = null;
            }

            catch (AutodiscoverLocalException ale)
            {
                Console.WriteLine("Błąd: {0}", ale.Message);
                //service = null;
            }

            // The credentials were authenticated. We expect this exception since we are providing intentional bad data for ConvertId
            catch (ServiceResponseException)
            {
                Console.WriteLine("Połączono z EWS.");
                authenticated = true;
            }

            // The credentials were not authenticated.
            catch (ServiceRequestException)
            {
                throw new ApplicationException("Dane dostępowe są nieważne.");
                //service = null;
            }

               return authenticated;
        }
开发者ID:KamilZet,项目名称:zalacznikX,代码行数:59,代码来源:CredentialHelper.cs

示例2: Authenticate

        /// <summary>
        /// Authenticates using the credentials provided to the credential manager. It also 
        /// populates the ExchangeService object used by the application.
        /// </summary>
        /// <param name="data">users data : name, password, email, domain</param>
        /// <param name="service">The ExchangeService object for this application.</param>
        /// <returns>A value of true indicates that the client successfully authenticated with EWS.</returns>
        private static bool Authenticate(IUserData data, ref ExchangeService service)
        {
            bool authenticated = false;
            try
            {
                service.Credentials = new WebCredentials(data.UserName, data.Password, data.Domain);

                // Check if we have the service URL.
                if (service.Url == null
                    || string.IsNullOrWhiteSpace(service.Url.OriginalString))
                {
                    Logger.Message(
                        LocalizibleStrings.StartAutodiscover, data.EmailAddress);
                    service.AutodiscoverUrl(
                        data.EmailAddress, Service.RedirectionUrlValidationCallback);
                    Logger.Message(LocalizibleStrings.AutodiscoverComplete);
                }

                // Once we have the URL, try a ConvertId operation to check if we can access the service. We expect that
                // the user will be authenticated and that we will get an error code due to the invalid format. Expect a
                // ServiceResponseException.
                Logger.Message(LocalizibleStrings.AttemptingConnectEws);
                service.ConvertId(new AlternateId(IdFormat.EwsId, @"Placeholder", data.UserName), IdFormat.EwsId);
            }
            // The user principal name is in a bad format.
            catch (FormatException fe)
            {
                Logger.Error(LocalizibleStrings.AuthInvalidUpn, fe);
            }
            catch (AutodiscoverLocalException ale)
            {
                Logger.Error(LocalizibleStrings.Auth, ale);
            }
            // The credentials were authenticated. We expect this exception since we are providing intentional bad data for ConvertId
            catch (ServiceResponseException)
            {
                Logger.Message(LocalizibleStrings.SuccConnection);
                authenticated = true;
            }
            // The credentials were not authenticated.
            catch (ServiceRequestException exc)
            {
                Logger.Error(LocalizibleStrings.CredNotAuth, exc);
            }
            return authenticated;
        }
开发者ID:nsobiratel,项目名称:MailGen,代码行数:53,代码来源:CredentialHelper.cs


注:本文中的ExchangeService.ConvertId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。