示例#1
0
        static void Descoberta()
        {
            Uri local = new Uri("https://disco.crm2.dynamics.com/XRMServices/2011/Discovery.svc");

            ClientCredentials clientecred = new ClientCredentials();

            clientecred.UserName.UserName = "******";
            clientecred.UserName.Password = "******";

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            DiscoveryServiceProxy dsp = new DiscoveryServiceProxy(local, null, clientecred, null);

            dsp.Authenticate();

            RetrieveOrganizationsRequest rosreq = new RetrieveOrganizationsRequest();

            rosreq.AccessType = EndpointAccessType.Default;
            rosreq.Release    = OrganizationRelease.Current;

            RetrieveOrganizationsResponse response = (RetrieveOrganizationsResponse)dsp.Execute(rosreq);

            foreach (var item in response.Details)
            {
                Console.WriteLine("Unique " + item.UniqueName);
                Console.WriteLine("Friendly " + item.FriendlyName);
                foreach (var endpoints in item.Endpoints)
                {
                    Console.WriteLine(endpoints.Key);
                    Console.WriteLine(endpoints.Value);
                }
            }
        }
        private void GetOrganizationCollection(object monitorSync, Uri discoveryUri, out OrganizationDetailCollection orgs)
        {
            IServiceManagement <IDiscoveryService> serviceManagement;

            try
            {
                serviceManagement = ServiceConfigurationFactory.CreateManagement <IDiscoveryService>(discoveryUri);
            }
            catch (Exception)
            {
                orgs = null;
                return;
            }
            AuthenticationProviderType endpointType = serviceManagement.AuthenticationType;

            AuthenticationCredentials authCredentials = GetCredentials(serviceManagement, endpointType);

            using (DiscoveryServiceProxy discoveryProxy =
                       GetProxy <IDiscoveryService, DiscoveryServiceProxy>(serviceManagement, authCredentials))
            {
                orgs = DiscoverOrganizations(discoveryProxy);
            }
            lock (monitorSync)
            {
                Monitor.Pulse(monitorSync);
            }
        }
示例#3
0
        static void Main(string[] args)
        {
            Uri local = new Uri("https://disco.crm2.dynamics.com/XRMServices/2011/Discovery.svc");

            ClientCredentials clientcred = new ClientCredentials();

            clientcred.UserName.UserName = lerEntradaCmd("Digite o Usuário");
            clientcred.UserName.Password = lerEntradaCmd("Digite a Senha");

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            DiscoveryServiceProxy dsp = new DiscoveryServiceProxy(local, null, clientcred, null);

            dsp.Authenticate();

            RetrieveOrganizationsRequest rosreq = new RetrieveOrganizationsRequest();

            rosreq.AccessType = EndpointAccessType.Default;
            rosreq.Release    = OrganizationRelease.Current;

            RetrieveOrganizationsResponse r = (RetrieveOrganizationsResponse)dsp.Execute(rosreq);

            foreach (var item in r.Details)
            {
                Console.WriteLine("Nome " + item.UniqueName);
                Console.WriteLine("Nome Exibição " + item.FriendlyName);
                foreach (var endpoint in item.Endpoints)
                {
                    Console.WriteLine(endpoint.Key);
                    Console.WriteLine(endpoint.Value);
                }
            }

            Console.ReadLine();
        }
        private string GetCurrentOrganizationName(ServerConnection.Configuration serverConfig)
        {
            using (DiscoveryServiceProxy _discoveryProxy = new DiscoveryServiceProxy(serverConfig.DiscoveryUri,
                                                                                     serverConfig.HomeRealmUri, serverConfig.Credentials, serverConfig.DeviceCredentials))
            {
                RetrieveOrganizationsRequest orgsRequest =
                    new RetrieveOrganizationsRequest()
                {
                    AccessType = EndpointAccessType.Default,
                    Release    = OrganizationRelease.Current
                };
                RetrieveOrganizationsResponse organizations =
                    (RetrieveOrganizationsResponse)_discoveryProxy.Execute(orgsRequest);

                foreach (OrganizationDetail organization in organizations.Details)
                {
                    foreach (var endpoint in organization.Endpoints)
                    {
                        if (endpoint.Value.ToLowerInvariant() == serverConfig.OrganizationUri.ToString().ToLowerInvariant())
                        {
                            return(organization.FriendlyName);
                        }
                    }
                }
            }
            return(String.Empty);
        }
示例#5
0
        /// <summary>
        /// obtém o endereço do serviço do CRM 2011.
        /// </summary>
        /// <param name="discoveryServiceUri">URI do Discovery Service CRM 2011</param>
        /// <param name="organization">Organização.</param>
        /// <returns></returns>
        protected virtual Uri GetOrganizationAddress(Uri discoveryServiceUri, string organization)
        {
            Uri organizationAddress = GetOrganizationAddress(organization, Organizations);

            if (organizationAddress == null)
            {
                //using (DiscoveryServiceProxy serviceProxy = GetDiscoveryProxy())
                using (DiscoveryServiceProxy serviceProxy = this.DiscoveryService)
                {
                    if (serviceProxy == null)
                    {
                        throw new ArgumentException("Servidor informado no arquivo de configuração é inválido ");
                    }

                    OrganizationDetailCollection orgs = DiscoverOrganizations(serviceProxy);
                    if (orgs == null || orgs.Count == 0)
                    {
                        throw new ArgumentException("Usuário informado não possui nenhuma organização.");
                    }

                    for (int index = 0; index < orgs.Count; index++)
                    {
                        if (orgs[index].UniqueName.ToUpper() != organization.ToUpper())
                        {
                            continue;
                        }

                        organizationAddress = new Uri(orgs[index].Endpoints[EndpointType.OrganizationService]);
                        break;
                    }
                }
            }
            return(organizationAddress);
        }
        /// <summary>
        /// Get the discovery service proxy based on existing configuration data.
        /// Added new way of getting discovery proxy.
        /// Also preserving old way of getting discovery proxy to support old scenarios.
        /// </summary>
        /// <returns>An instance of DiscoveryServiceProxy</returns>
        private DiscoveryServiceProxy GetDiscoveryProxy()
        {
            try
            {
                // Obtain the discovery service proxy.
                DiscoveryServiceProxy discoveryProxy = GetProxy <IDiscoveryService, DiscoveryServiceProxy>(this.config, this.ConfigurationProvider);
                // Checking authentication by invoking some SDK methods.
                discoveryProxy.Execute(new RetrieveOrganizationsRequest());
                return(discoveryProxy);
            }
            catch (System.ServiceModel.Security.SecurityAccessDeniedException ex)
            {
                // If authentication failed using current UserPrincipalName,
                // request UserName and Password to try to authenticate using user credentials.
                if (!String.IsNullOrWhiteSpace(config.UserPrincipalName) &&
                    ex.Message.Contains("Access is denied."))
                {
                    config.AuthFailureCount += 1;
                }
                else
                {
                    throw ex;
                }
            }
            // You can also catch other exceptions to handle a specific situation in your code, for example,
            //      System.ServiceModel.Security.ExpiredSecurityTokenException
            //      System.ServiceModel.Security.MessageSecurityException
            //      System.ServiceModel.Security.SecurityNegotiationException

            // Second trial to obtain the discovery service proxy in case of single sign-on failure.
            return(GetProxy <IDiscoveryService, DiscoveryServiceProxy>(this.config, this.ConfigurationProvider));
        }
        protected virtual Uri GetOrganizationAddress(Uri discoveryServiceUri, string orgName)
        {
            using (DiscoveryServiceProxy serviceProxy = new DiscoveryServiceProxy(discoveryServiceUri, null, config.Credentials, config.DeviceCredentials))
            {
                // Obtain organization information from the Discovery service. 
                if (serviceProxy != null)
                {
                    // Obtain information about the organizations that the system user belongs to.
                    OrganizationDetailCollection orgs = DiscoverOrganizations(serviceProxy);

                    OrganizationDetail org = orgs.Where(x => x.UniqueName.ToLower() == orgName.ToLower()).FirstOrDefault();

                    if (org != null)
                    {
                        return new System.Uri(org.Endpoints[EndpointType.OrganizationService]);
                    }
                    else
                    {
                        throw new InvalidOperationException("That OrgName does not exist on that server.");
                    }
                }
                else
                    throw new Exception("An invalid server name was specified.");
            }
        }
        /// <summary>
        ///
        /// </summary>
        public OrganizationServiceProxy GetOrganizationProxy()
        {
            IServiceManagement <IDiscoveryService> serviceManagement = ServiceConfigurationFactory.CreateManagement <IDiscoveryService>(new Uri(DiscoveryServiceAddress));
            AuthenticationProviderType             endpointType      = serviceManagement.AuthenticationType;
            AuthenticationCredentials authCredentials = GetCredentials(serviceManagement, endpointType);


            String organizationUri = String.Empty;

            // Get the discovery service proxy.
            using (DiscoveryServiceProxy discoveryProxy = GetProxy <IDiscoveryService, DiscoveryServiceProxy>(serviceManagement, authCredentials))
            {
                // Obtain organization information from the Discovery service.
                if (discoveryProxy != null)
                {
                    // Obtain information about the organizations that the system user belongs to.
                    OrganizationDetailCollection orgs = DiscoverOrganizations(discoveryProxy);
                    // Obtains the Web address (Uri) of the target organization.
                    organizationUri = FindOrganization(OrganizationUniqueName, orgs.ToArray()).Endpoints[EndpointType.OrganizationService];
                }
            }


            IServiceManagement <IOrganizationService> orgServiceManagement = ServiceConfigurationFactory.CreateManagement <IOrganizationService>(new Uri(organizationUri));

            // Set the credentials.
            AuthenticationCredentials credentials = GetCredentials(orgServiceManagement, endpointType);

            // Get the organization service proxy.
            return(GetProxy <IOrganizationService, OrganizationServiceProxy>(orgServiceManagement, credentials));
        }
        public static OrganizationDetailCollection GetOrganizations(Settings settings)
        {
            var credentials = new ClientCredentials();

            if (settings.UseIFD || settings.UseOffice365 || settings.UseOnline)
            {
                credentials.UserName.UserName = settings.Username;
                credentials.UserName.Password = settings.Password;
            }
            else
            {
                credentials.Windows.ClientCredential =
                    new System.Net.NetworkCredential(settings.Username, settings.Password, settings.Domain);
            }

            using (var discoveryProxy = new DiscoveryServiceProxy(settings.GetDiscoveryUri(), null, credentials, null))
            {
                discoveryProxy.Authenticate();

                var retrieveOrganizationsRequest = new RetrieveOrganizationsRequest
                {
                    AccessType = EndpointAccessType.Default,
                    Release    = OrganizationRelease.Current
                };

                var retrieveOrganizationsResponse = (RetrieveOrganizationsResponse)discoveryProxy
                                                    .Execute(retrieveOrganizationsRequest);

                return(retrieveOrganizationsResponse.Details);
            }
        }
示例#10
0
        public static void Main(string[] args)
        {
            try
            {
                var crmUrl      = ConfigurationManager.AppSettings["CrmUrl"];
                var url         = new Uri(crmUrl + "/XRMServices/2011/Discovery.svc");
                var config      = ServiceConfigurationFactory.CreateConfiguration <IDiscoveryService>(url);
                var credentials = new ClientCredentials();
                credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
                var discoveryService = new DiscoveryServiceProxy(config, credentials);
                discoveryService.Authenticate();
                var request  = new RetrieveOrganizationsRequest();
                var response = (RetrieveOrganizationsResponse)discoveryService.Execute(request);

                foreach (var detail in response.Details)
                {
                    var organizationServiceUrl = detail.Endpoints[EndpointType.OrganizationService];
                    var organizationName       = detail.UniqueName;
                    GetOrganizationInfo(organizationName, organizationServiceUrl);
                }
                Console.WriteLine("Press any key to close the window.");
                Console.ReadKey();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error occured." + Environment.NewLine + ex.ToString());
            }
        }
        private static OrganizationDetailCollection DiscoverOrganizations(DiscoveryServiceProxy service)
        {
            RetrieveOrganizationsRequest request = new RetrieveOrganizationsRequest();
            RetrieveOrganizationsResponse response = (RetrieveOrganizationsResponse)service.Execute(request);

            return response.Details;
        }
        private static IOrganizationService Connect()
        {
            var config = _configurationService.Get <XrmClientConfiguration>();


            Uri dInfo = new Uri(config.XrmUri);
            ClientCredentials clientcred = new ClientCredentials();

            clientcred.UserName.UserName = config.XrmClientCredUserName;
            clientcred.UserName.Password = config.XrmClientCredPassword;


            #region on-premise/online

            DiscoveryServiceProxy dsp = new DiscoveryServiceProxy(dInfo, null, clientcred, null);
            dsp.Authenticate();
            RetrieveOrganizationsRequest  rosreq = new Microsoft.Xrm.Sdk.Discovery.RetrieveOrganizationsRequest();
            RetrieveOrganizationsResponse r      = (RetrieveOrganizationsResponse)dsp.Execute(rosreq);

            //get the OrganizationService
            ManagedTokenOrganizationServiceProxy _serviceproxy = new ManagedTokenOrganizationServiceProxy(new Uri(config.XrmOrgServiceProxy), clientcred);
            //In order to use the generated types when dealing with the organization service, you have to add the ProxyTypesBehavior to the endpoint Behaviors collection. This instructs the OrganizationServiceProxy to look in the assembly for classes with certain attributes to use. The generated classes are already attributed with these attributes. Simply, this makes all interactions with the organization service to be done using the generated typed classes for each entity instead of the generic Entity class we used earlier.
            _serviceproxy.ServiceConfiguration.CurrentServiceEndpoint.EndpointBehaviors.Add(new ProxyTypesBehavior());
            //Do not forget to include _serviceproxy.EnableProxyTypes();. Without this line,you will be unable to use early binding.
            _serviceproxy.EnableProxyTypes();
            IOrganizationService service = (IOrganizationService)_serviceproxy;

            #endregion
            return(service);
        }
        public static List <string> GetOrganizations(string url, string domain, string username, string password)
        {
            var results = new List <string>()
            {
            };
            var credentials = GetCredentials(url, domain, username, password);
            ClientCredentials deviceCredentials = null;

            if (url.IndexOf("dynamics.com", StringComparison.InvariantCultureIgnoreCase) > -1)
            {
                deviceCredentials = DeviceIdManager.LoadOrRegisterDevice(new Guid());   // TODO this was failing with some online connections
            }

            using (DiscoveryServiceProxy disco = new DiscoveryServiceProxy(new Uri(url), null, credentials, deviceCredentials))
            {
                if (disco != null)
                {
                    OrganizationDetailCollection orgs = DiscoverOrganizations(disco);
                    if (orgs.Count > 0)
                    {
                        results = orgs.Select(o => o.FriendlyName).ToList();
                    }
                }
            }

            return(results);
        }
        private static OrganizationDetailCollection DiscoverOrganizations(DiscoveryServiceProxy service)
        {
            RetrieveOrganizationsRequest  request  = new RetrieveOrganizationsRequest();
            RetrieveOrganizationsResponse response = (RetrieveOrganizationsResponse)service.Execute(request);

            return(response.Details);
        }
示例#15
0
        /// <summary>
        ///
        /// </summary>
        public void Run()
        {
            //<snippetAuthenticateWithNoHelp1>
            IServiceManagement <IDiscoveryService> serviceManagement =
                ServiceConfigurationFactory.CreateManagement <IDiscoveryService>(
                    new Uri(_discoveryServiceAddress));
            AuthenticationProviderType endpointType = serviceManagement.AuthenticationType;

            // Set the credentials.
            AuthenticationCredentials authCredentials = GetCredentials(serviceManagement, endpointType);


            String organizationUri = String.Empty;

            // Get the discovery service proxy.
            using (DiscoveryServiceProxy discoveryProxy =
                       GetProxy <IDiscoveryService, DiscoveryServiceProxy>(serviceManagement, authCredentials))
            {
                // Obtain organization information from the Discovery service.
                if (discoveryProxy != null)
                {
                    // Obtain information about the organizations that the system user belongs to.
                    OrganizationDetailCollection orgs = DiscoverOrganizations(discoveryProxy);
                    // Obtains the Web address (Uri) of the target organization.
                    organizationUri = FindOrganization(_organizationUniqueName,
                                                       orgs.ToArray()).Endpoints[EndpointType.OrganizationService];
                }
            }
            //</snippetAuthenticateWithNoHelp1>


            if (!String.IsNullOrWhiteSpace(organizationUri))
            {
                //<snippetAuthenticateWithNoHelp3>
                IServiceManagement <IOrganizationService> orgServiceManagement =
                    ServiceConfigurationFactory.CreateManagement <IOrganizationService>(
                        new Uri(organizationUri));

                // Set the credentials.
                AuthenticationCredentials credentials = GetCredentials(orgServiceManagement, endpointType);

                // Get the organization service proxy.
                using (OrganizationServiceProxy organizationProxy =
                           GetProxy <IOrganizationService, OrganizationServiceProxy>(orgServiceManagement, credentials))
                {
                    // This statement is required to enable early-bound type support.
                    organizationProxy.EnableProxyTypes();

                    // Now make an SDK call with the organization service proxy.
                    // Display information about the logged on user.
                    Guid userid = ((WhoAmIResponse)organizationProxy.Execute(
                                       new WhoAmIRequest())).UserId;
                    SystemUser systemUser = organizationProxy.Retrieve("systemuser", userid,
                                                                       new ColumnSet(new string[] { "firstname", "lastname" })).ToEntity <SystemUser>();
                    Console.WriteLine("Logged on user is {0} {1}.",
                                      systemUser.FirstName, systemUser.LastName);
                }
                //</snippetAuthenticateWithNoHelp3>
            }
        }
        protected virtual Uri GetOrganizationAddress(Uri discoveryServiceUri, string orgName)
        {
            using (DiscoveryServiceProxy _serviceProxy = ServerConnection.GetProxy <IDiscoveryService, DiscoveryServiceProxy>(config))
            {
                // Obtain organization information from the Discovery service.
                if (_serviceProxy != null)
                {
                    // Obtain information about the organizations that the system user belongs to.
                    OrganizationDetailCollection orgs = DiscoverOrganizations(_serviceProxy);

                    OrganizationDetail org = orgs.Where(x => x.UniqueName.ToLower() == orgName.ToLower()).FirstOrDefault();

                    if (org != null)
                    {
                        return(new System.Uri(org.Endpoints[EndpointType.OrganizationService]));
                    }
                    else
                    {
                        throw new InvalidOperationException("That OrgName does not exist on that server.");
                    }
                }
                else
                {
                    throw new Exception("An invalid server name was specified.");
                }
            }
        }
示例#17
0
        public static DiscoveryServiceProxy InitializeDiscoveryService(string serverUrl, string orgName, string deploymentType, string userName, string password)
        {
            Console.WriteLine(string.Format("Initializing discovery service to '{0}'", serverUrl));

            var credentials = new ClientCredentials();

            if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password))
            {
                credentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
            }
            else
            {
                credentials.UserName.UserName = userName;
                credentials.UserName.Password = password;
            }

            Uri crmServerUrl;

            if (deploymentType.Equals("CrmOnline", StringComparison.InvariantCultureIgnoreCase))
            {
                crmServerUrl = new Uri(string.Format("{0}/XRMServices/2011/Discovery.svc", serverUrl));
            }
            else
            {
                crmServerUrl = new Uri(string.Format("{0}/{1}/XRMServices/2011/Discovery.svc", serverUrl, orgName));
            }

            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

            using (DiscoveryServiceProxy serviceProxy = new DiscoveryServiceProxy(crmServerUrl, null, credentials, null))
            {
                serviceProxy.Timeout = new TimeSpan(4, 0, 0);
                return(serviceProxy);
            }
        }
示例#18
0
        /// <summary>
        /// Get the discovery service proxy based on existing configuration data.
        /// Added new way of getting discovery proxy.
        /// Also preserving old way of getting discovery proxy to support old scenarios.
        /// </summary>
        /// <returns>An instance of DiscoveryServiceProxy</returns>
        private DiscoveryServiceProxy GetDiscoveryProxy()
        {
            IServiceManagement <IDiscoveryService> serviceManagement = ServiceConfigurationFactory.CreateManagement <IDiscoveryService>(DiscoveryUri);

            Authentication = serviceManagement.AuthenticationType;

            // Get the logon credentials.
            _userCredentials = GetUserLogonCredentials(this._user, this._password, this._domain);

            AuthenticationCredentials authCredentials = new AuthenticationCredentials();

            if (!String.IsNullOrWhiteSpace(this.UserPrincipalName))
            {
                // Try to authenticate the Federated Identity organization with UserPrinicipalName.
                authCredentials.UserPrincipalName = this.UserPrincipalName;
                try
                {
                    AuthenticationCredentials tokenCredentials = serviceManagement.Authenticate(authCredentials);
                    DiscoveryServiceProxy     discoveryProxy   = new DiscoveryServiceProxy(serviceManagement, tokenCredentials.SecurityTokenResponse);
                    // Checking authentication by invoking some SDK methods.
                    OrganizationDetailCollection orgs = DiscoverOrganizations(discoveryProxy);
                    return(discoveryProxy);
                }
                catch (System.ServiceModel.Security.SecurityAccessDeniedException ex)
                {
                    // If authentication failed using current UserPrincipalName,
                    // request UserName and Password to try to authenticate using user credentials.
                    if (ex.Message.Contains("Access is denied."))
                    {
                        this.AuthFailureCount            += 1;
                        authCredentials.UserPrincipalName = String.Empty;

                        _userCredentials = GetUserLogonCredentials(this._user, this._password, this._domain);
                    }
                    else
                    {
                        throw ex;
                    }
                }
            }

            // Resetting credentials in the AuthenicationCredentials.
            if (Authentication != AuthenticationProviderType.ActiveDirectory)
            {
                authCredentials = new AuthenticationCredentials();
                authCredentials.ClientCredentials = UserCredentials;

                if (Authentication == AuthenticationProviderType.LiveId)
                {
                    authCredentials.SupportingCredentials = new AuthenticationCredentials();
                    authCredentials.SupportingCredentials.ClientCredentials = UserCredentials;
                }
                // Try to authenticate with the user credentials.
                AuthenticationCredentials tokenCredentials1 = serviceManagement.Authenticate(authCredentials);
                return(new DiscoveryServiceProxy(serviceManagement, tokenCredentials1.SecurityTokenResponse));
            }
            // For an on-premises environment.
            return(new DiscoveryServiceProxy(serviceManagement, UserCredentials));
        }
 /// <summary>
 /// Helper method for assigning common proxy-specific settings such as channel timeout
 /// </summary>
 /// <param name="proxy">The service proxy</param>
 /// <param name="options">The options to configure on the service proxy</param>
 public static void SetProxyOptions(this DiscoveryServiceProxy proxy, DiscoveryServiceProxyOptions options)
 {
     if (!options.Timeout.Equals(TimeSpan.Zero) &&
         options.Timeout > TimeSpan.Zero)
     {
         proxy.Timeout = options.Timeout;
     }
 }
        private static IOrganizationService ConnectToCRM()
        {
            #region connect to D365 online

            var appSettings = ConfigurationManager.AppSettings;
            if (appSettings["discoveryService"] == null || appSettings["orgService"] == null)
            {
                Connection.Result = false;
                return(null);
            }


            Uri dInfo = new Uri(appSettings["discoveryService"]);
            ClientCredentials clientcred = new ClientCredentials();
            if (Connection.UserName == null || Connection.Password == null)
            {
                return(null);
            }
            clientcred.UserName.UserName = Connection.UserName;
            clientcred.UserName.Password = Connection.Password;
            DiscoveryServiceProxy dsp = new DiscoveryServiceProxy(dInfo, null, clientcred, null);
            try
            {
                dsp.Authenticate();
                Connection.Result = true;
            }
            catch (Exception)
            {
                Connection.Result = false;
                return(null);
            }


            RetrieveOrganizationsRequest  rosreq     = new RetrieveOrganizationsRequest();
            RetrieveOrganizationsResponse retieveOrg = (RetrieveOrganizationsResponse)dsp.Execute(rosreq);

            //get the OrganizationService
            OrganizationServiceProxy _serviceproxy = new OrganizationServiceProxy(new Uri(appSettings["orgService"]), null, clientcred, null);
            _serviceproxy.ServiceConfiguration.CurrentServiceEndpoint.EndpointBehaviors.Add(new ProxyTypesBehavior());
            _serviceproxy.EnableProxyTypes();
            IOrganizationService service = (IOrganizationService)_serviceproxy;

            foreach (OrganizationDetail o in retieveOrg.Details)
            {
                //lblOrg.Text = o.FriendlyName;
                //WhoAmIResponse whoAMIResponse = (WhoAmIResponse)service.Execute(new Microsoft.Crm.Sdk.Messages.WhoAmIRequest());
                //lblUser.Text = whoAMIResponse.UserId.ToString();
                break;
            }

            #endregion
            return(service);
        }
示例#21
0
        public Microsoft.Xrm.Sdk.IOrganizationService GetService(string serverURL, string userName, string userPassword, string userDomain, string organizationCRM)
        {
            //to ignore certificates errors
            ServicePointManager.ServerCertificateValidationCallback =
                new RemoteCertificateValidationCallback(AcceptAllCertificatePolicy);

            IServiceManagement <IDiscoveryService> serviceManagement =
                ServiceConfigurationFactory.CreateManagement <IDiscoveryService>(
                    new Uri(string.Format("{0}/XRMServices/2011/Discovery.svc", serverURL)));
            AuthenticationProviderType endpointType = serviceManagement.AuthenticationType;

            // Set the credentials.
            AuthenticationCredentials authCredentials = GetCredentials(endpointType, userName, userPassword, userDomain);

            String organizationUri = String.Empty;

            // Get the discovery service proxy.
            DiscoveryServiceProxy discoveryProxy =
                GetProxy <IDiscoveryService, DiscoveryServiceProxy>(serviceManagement, authCredentials);

            // Obtain organization information from the Discovery service.
            if (discoveryProxy != null)
            {
                // Obtain information about the organizations that the system user belongs to.
                OrganizationDetailCollection orgs = DiscoverOrganizations(discoveryProxy);
                // Obtains the Web address (Uri) of the target organization.
                organizationUri = FindOrganization(organizationCRM,
                                                   orgs.ToArray()).Endpoints[EndpointType.OrganizationService];
            }


            if (!String.IsNullOrWhiteSpace(organizationUri))
            {
                IServiceManagement <IOrganizationService> orgServiceManagement =
                    ServiceConfigurationFactory.CreateManagement <IOrganizationService>(
                        new Uri(organizationUri));

                // Set the credentials.
                AuthenticationCredentials credentials = GetCredentials(endpointType, userName, userPassword, userDomain);

                // Get the organization service proxy.
                OrganizationServiceProxy organizationProxy =
                    GetProxy <IOrganizationService, OrganizationServiceProxy>(orgServiceManagement, credentials);

                // This statement is required to enable early-bound type support.
                organizationProxy.EnableProxyTypes();

                return(organizationProxy);
            }

            return(null);
        }
        public OrganizationDetailCollection GetOrganizationAddressesAsList(ServerConnection.Configuration config)
        {
            OrganizationDetailCollection orgs = new OrganizationDetailCollection();

            using (DiscoveryServiceProxy serviceProxy = GetDiscoveryProxy(config)) {
                // Obtain organization information from the Discovery service.
                if (serviceProxy != null)
                {
                    orgs = DiscoverOrganizations(serviceProxy);
                }
            }
            return(orgs);
        }
        /// <summary>
        /// Obtains the Web address (Uri) of the target organization.
        /// </summary>
        /// <param name="discoveryServiceUri">The Uri of the CRM Discovery service.</param>
        /// <returns>Uri of the organization service or an empty string.</returns>
        protected virtual Uri GetOrganizationAddress(Uri discoveryServiceUri)
        {
            using (DiscoveryServiceProxy serviceProxy = new DiscoveryServiceProxy(discoveryServiceUri, null, config.Credentials, config.DeviceCredentials))
            {
                // Obtain organization information from the Discovery service.
                if (serviceProxy != null)
                {
                    // Obtain information about the organizations that the system user belongs to.
                    OrganizationDetailCollection orgs = DiscoverOrganizations(serviceProxy);

                    if (orgs.Count > 0)
                    {
                        Console.WriteLine("\nList of organizations that you belong to:");
                        for (int n = 0; n < orgs.Count; n++)
                        {
                            Console.Write("\n({0}) {1} ({2})\t", n + 1, orgs[n].FriendlyName, orgs[n].UrlName);
                        }

                        Console.Write("\n\nSpecify an organization number (1-{0}) [1]: ", orgs.Count);
                        String input = Console.ReadLine();
                        if (input == String.Empty)
                        {
                            input = "1";
                        }
                        int orgNumber = Int32.Parse(input);

                        if (orgNumber > 0 && orgNumber <= orgs.Count)
                        {
                            config.OrganizationName = orgs[orgNumber - 1].FriendlyName;
                            // Return the organization Uri.
                            return(new System.Uri(orgs[orgNumber - 1].Endpoints[EndpointType.OrganizationService]));
                        }
                        else
                        {
                            throw new Exception("The specified organization does not exist.");
                        }
                    }
                    else
                    {
                        Console.WriteLine("\nYou do not belong to any organizations on the specified server.");
                        return(new System.Uri(String.Empty));
                    }
                }
                else
                {
                    throw new Exception("An invalid server name was specified.");
                }
            }
        }
示例#24
0
        /// <summary>
        /// Configures the connector in IFD mode.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        private void ConfigureIfdConnection(IConfigurationProvider configuration)
        {
            var userCredentials = new ClientCredentials();

            userCredentials.UserName.UserName = configuration.CrmUserDomain + @"\" + configuration.CrmUserName;
            userCredentials.UserName.Password = configuration.CrmPassword;

            var discoveryConfiguration = CreateDiscoveryConfiguration(configuration);
            var userResponseWrapper    = discoveryConfiguration.Authenticate(userCredentials);

            this.discoveryService = new DiscoveryServiceProxy(discoveryConfiguration, userResponseWrapper);

            var serviceConfiguration = this.CreateServiceConfiguration(configuration);

            this.organizationService = new OrganizationServiceProxy(serviceConfiguration, userResponseWrapper);
            this.organizationService.EnableProxyTypes();
        }
示例#25
0
        private void button1_Click(object sender, EventArgs e)
        {
            userCred = new ClientCredentials();
            userCred.UserName.UserName = "******";
            userCred.UserName.Password = "******";

            deviceCred = new ClientCredentials();
            deviceCred.UserName.UserName = "******";
            deviceCred.UserName.Password = "******";

            var discoUrl = "https://disco.crm11.dynamics.com/XRMServices/2011/Discovery.svc";

            using (var serviceProxy = new DiscoveryServiceProxy(new Uri(discoUrl), null, userCred, deviceCred))
            {
                var orgProxy = GetInfo(serviceProxy);
            }
        }
 /// <summary>
 /// Obtains the web address (Uri) of the target organization.
 /// </summary>
 /// <returns>Uri of the organization service or an empty string.</returns>
 protected Uri GetOrganizationAddress()
 {
     using (DiscoveryServiceProxy serviceProxy = GetDiscoveryProxy())
     {
         // Obtain organization information from the Discovery service.
         if (serviceProxy != null)
         {
             config.OrganizationName = this.ConfigurationProvider.GetConfigurationSettingValue("CRMInstanceName"); //"psareports";
             // Return the organization Uri.
             return(new System.Uri(String.Format("https://{0}.api.crm.dynamics.com/XRMServices/2011/Organization.svc", config.OrganizationName)));
         }
         else
         {
             throw new InvalidOperationException("An invalid server name was specified.");
         }
     }
 }
 /// <summary>
 /// Obtains the web address (Uri) of the target organization.
 /// </summary>
 /// <returns>Uri of the organization service or an empty string.</returns>
 protected virtual OrganizationDetailCollection GetOrganizationAddress()
 {
     using (DiscoveryServiceProxy serviceProxy = GetDiscoveryProxy())
     {
         // Obtain organization information from the Discovery service.
         if (serviceProxy != null)
         {
             // Obtain information about the organizations that the system user belongs to.
             organizations = DiscoverOrganizations(serviceProxy);
             return(organizations);
         }
         else
         {
             throw new Exception("An invalid server name was specified.");
         }
     }
 }
示例#28
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (this.discoveryService != null)
                {
                    this.discoveryService.Dispose();
                    this.discoveryService = null;
                }

                if (this.organizationService != null)
                {
                    this.organizationService.Dispose();
                    this.organizationService = null;
                }
            }
        }
        private List <D365Organization> RetrieveOrganizations(string userName, string password, string domain, string discoveryUrl)
        {
            List <D365Organization> result = null;
            IServiceManagement <IDiscoveryService> serviceManagement = ServiceConfigurationFactory.CreateManagement <IDiscoveryService>(new Uri(discoveryUrl + "/XRMServices/2011/Discovery.svc"));
            AuthenticationProviderType             endpointType      = serviceManagement.AuthenticationType;

            // Set the credentials.
            AuthenticationCredentials authCredentials = GetCredentials(userName, password, null, serviceManagement, endpointType);

            try
            {
                // Get the discovery service proxy.
                using (DiscoveryServiceProxy discoveryProxy = GetProxy <IDiscoveryService, DiscoveryServiceProxy>(serviceManagement, authCredentials))
                {
                    // Obtain organization information from the Discovery service.
                    if (discoveryProxy != null)
                    {
                        // Obtain information about the organizations that the system user belongs to.
                        var orgs = DiscoverOrganizations(discoveryProxy);
                        if (orgs != null)
                        {
                            result = new List <D365Organization>();
                            foreach (OrganizationDetail o in orgs)
                            {
                                if (o.State == OrganizationState.Enabled)
                                {
                                    result.Add(new D365Organization
                                    {
                                        ConnectorUrl = discoveryUrl,
                                        Id           = o.UniqueName,
                                        Name         = o.FriendlyName
                                    });
                                }
                            }
                        }
                    }
                }
            }
            catch
            {
                // do nothing
            }

            return(result);
        }
示例#30
0
        /// <summary>
        /// Obtains the Web address (Uri) of the target organization.
        /// </summary>
        /// <param name="discoveryServiceUri">The Uri of the CRM Discovery service.</param>
        /// <param name="organizationName">Organization name</param>
        /// <returns>Uri of the organization service or an empty string.</returns>
        protected virtual Uri GetOrganizationAddress(Uri discoveryServiceUri, string organizationName)
        {
            using (DiscoveryServiceProxy serviceProxy = new DiscoveryServiceProxy(discoveryServiceUri, null, this.config.Credentials, this.config.DeviceCredentials))
            {
                // Autentica las credenciales.
                serviceProxy.Authenticate();

                // Obtain organization information from the Discovery service.
                if (serviceProxy != null)
                {
                    // Obtain information about the organizations that the system user belongs to.
                    var orgs = DiscoverOrganizations(serviceProxy);

                    if (orgs.Count > 0)
                    {
                        if (!string.IsNullOrWhiteSpace(organizationName))
                        {
                            for (int n = 0; n < orgs.Count; n++)
                            {
                                if (orgs[n].UniqueName == organizationName)
                                {
                                    return(new System.Uri(orgs[n].Endpoints[EndpointType.OrganizationService]));
                                }
                            }

                            throw new Exception("An invalid server/organization name was specified.");
                        }
                        else
                        {
                            throw new Exception("An invalid server/organization name was specified.");
                        }
                    }
                    else
                    {
                        Console.WriteLine("\nYou do not belong to any organizations on the specified server.");
                        return(new Uri(string.Empty));
                    }
                }
                else
                {
                    throw new Exception("An invalid server name was specified.");
                }
            }
        }
        public static IOrganizationService Connect(string url, string domain, string username, string password, string organization)
        {
            //var connectionString = @"Url=" + url + "; Username="******"; password="******";";
            //var connection = new Microsoft.Xrm.Client.CrmConnection(connectionString);
            //var test = new Microsoft.Xrm.Client.Services.OrganizationService(connection);
            //return test;

            var credentials = GetCredentials(url, domain, username, password);
            ClientCredentials deviceCredentials = null;

            if (url.IndexOf("dynamics.com", StringComparison.InvariantCultureIgnoreCase) > -1)
            {
                deviceCredentials = DeviceIdManager.LoadOrRegisterDevice(new Guid());
            }

            Uri orgUri = null;
            OrganizationServiceProxy sdk = null;

            using (DiscoveryServiceProxy disco = new DiscoveryServiceProxy(new Uri(url), null, credentials, deviceCredentials))
            {
                if (disco != null)
                {
                    OrganizationDetailCollection orgs = DiscoverOrganizations(disco);
                    if (orgs.Count > 0)
                    {
                        var found = orgs.ToList()
                                    .Where(a => a.UniqueName.Equals(organization, StringComparison.InvariantCultureIgnoreCase))
                                    .Take(1).SingleOrDefault();

                        if (found != null)
                        {
                            orgUri = new Uri(found.Endpoints[EndpointType.OrganizationService]);
                        }
                    }
                }
            }

            if (orgUri != null)
            {
                sdk = new OrganizationServiceProxy(orgUri, null, credentials, deviceCredentials);
            }

            return(sdk);
        }
示例#32
0
        protected virtual DiscoveryServiceProxy ToDiscoveryServiceProxy(CrmConnection connection)
        {
            connection.ThrowOnNull("connection");
            if (connection.ServiceUri == null)
            {
                throw new ConfigurationErrorsException("The connection's 'ServiceUri' must be specified.");
            }

            var clientCredentials = connection.ClientCredentials;

            DiscoveryServiceProxy service;

            // retrieve the ServiceConfiguration from cache

            var config = GetServiceConfiguration(connection);

            var isClaimsMode = config.AuthenticationType == AuthenticationProviderType.Federation ||
                               config.AuthenticationType == AuthenticationProviderType.OnlineFederation ||
                               config.AuthenticationType == AuthenticationProviderType.LiveId;

            if (isClaimsMode && clientCredentials != null)
            {
                // get the user token for claims authentication

                var userTokenResponse = GetUserTokenResponse(connection, config);

                Assert(userTokenResponse != null && userTokenResponse.Token != null, "The user authentication failed!");

                service = new DiscoveryServiceProxy(config, userTokenResponse);
            }
            else
            {
                // AD authentication

                service = new DiscoveryServiceProxy(config, clientCredentials);
            }

            if (connection.Timeout != null)
            {
                service.Timeout = connection.Timeout.Value;
            }

            return(service);
        }
        public static IOrganizationService Connect(string url, string domain, string username, string password, string organization, out string publicUrl)
        {
            publicUrl = "";

            var credentials = GetCredentials(url, domain, username, password);
            ClientCredentials deviceCredentials = null;
            if (url.IndexOf("dynamics.com", StringComparison.InvariantCultureIgnoreCase) > -1)
            {
                deviceCredentials = Microsoft.Crm.Services.Utility.DeviceIdManager.LoadOrRegisterDevice();
            }

            Uri orgUri = null;
            OrganizationServiceProxy sdk = null;

            using (DiscoveryServiceProxy disco = new DiscoveryServiceProxy(new Uri(url), null, credentials, deviceCredentials))
            {
                if (disco != null)
                {
                    OrganizationDetailCollection orgs = DiscoverOrganizations(disco);
                    if (orgs.Count > 0)
                    {
                        var found = orgs.ToList()
                            .Where(a => a.UniqueName.Equals(organization, StringComparison.InvariantCultureIgnoreCase))
                            .Take(1).SingleOrDefault();

                        if (found != null)
                        {
                            orgUri = new Uri(found.Endpoints[EndpointType.OrganizationService]);
                            publicUrl = found.Endpoints[EndpointType.WebApplication];
                        }
                    }
                }
            }

            if (orgUri != null)
            {
                sdk = new OrganizationServiceProxy(orgUri, null, credentials, deviceCredentials);
            }

            return sdk;
        }
示例#34
0
        /// <summary>
        /// Demonstrates the RetrieveOrganization and RetrieveOrganizations messages
        /// of the Discovery service.
        /// </summary>
        /// <param name="serverConfig">Contains server connection information.</param>
        /// <param name="promptforDelete">When True, the user will be prompted to delete all
        /// created entities.</param>
        public void Run(ServerConnection.Configuration serverConfig, bool promptforDelete)
        {
            try
            {
                //<snippetDiscoveryService1>
                // Connect to the Discovery service. 
                // The using statement assures that the service proxy will be properly disposed.
                using (_serviceProxy = new DiscoveryServiceProxy(serverConfig.DiscoveryUri,
                                                                    serverConfig.HomeRealmUri,
                                                                    serverConfig.Credentials,
                                                                    serverConfig.DeviceCredentials))
                {
                    // You can choose to use the interface instead of the proxy.
                    IDiscoveryService service = _serviceProxy;

                    #region RetrieveOrganizations Message

                    //<snippetDiscoveryService2>
                    // Retrieve details about all organizations discoverable via the
                    // Discovery service.
                    RetrieveOrganizationsRequest orgsRequest =
                        new RetrieveOrganizationsRequest()
                        {
                            AccessType = EndpointAccessType.Default,
                            Release = OrganizationRelease.Current
                        };
                    RetrieveOrganizationsResponse organizations =
                        (RetrieveOrganizationsResponse)service.Execute(orgsRequest);
                    //</snippetDiscoveryService2>

                    // Print each organization's friendly name, unique name and URLs
                    // for each of its endpoints.
                    Console.WriteLine();
                    Console.WriteLine("Retrieving details of each organization:");
                    foreach (OrganizationDetail organization in organizations.Details)
                    {
                        Console.WriteLine("Organization Name: {0}", organization.FriendlyName);
                        Console.WriteLine("Unique Name: {0}", organization.UniqueName);
                        Console.WriteLine("Endpoints:");
                        foreach (var endpoint in organization.Endpoints)
                        {
                            Console.WriteLine("  Name: {0}", endpoint.Key);
                            Console.WriteLine("  URL: {0}", endpoint.Value);
                        }
                    }
                    Console.WriteLine("End of listing");
                    Console.WriteLine();

                    #endregion RetrieveOrganizations Message

                    #region RetrieveOrganization Message

                    //<snippetDiscoveryService3>
                    // Retrieve details about a single organization discoverable via the Discovery service.
                    //
                    RetrieveOrganizationRequest orgRequest =
                        new RetrieveOrganizationRequest()
                        {
                            UniqueName = organizations.Details[organizations.Details.Count -1].UniqueName,
                            AccessType = EndpointAccessType.Default,
                            Release = OrganizationRelease.Current
                        };
                    RetrieveOrganizationResponse org =
                        (RetrieveOrganizationResponse)service.Execute(orgRequest);
                    //</snippetDiscoveryService3>

                    // Print the organization's friendly name, unique name and URLs
                    // for each of its endpoints.
                    Console.WriteLine();
                    Console.WriteLine("Retrieving details of specific organization:");
                    Console.WriteLine("Organization Name: {0}", org.Detail.FriendlyName);
                    Console.WriteLine("Unique Name: {0}", org.Detail.UniqueName);
                    Console.WriteLine("Endpoints:");
                    foreach (KeyValuePair<EndpointType, string> endpoint in org.Detail.Endpoints)
                    {
                        Console.WriteLine("  Name: {0}", endpoint.Key);
                        Console.WriteLine("  URL: {0}", endpoint.Value);
                    }
                    Console.WriteLine("End of listing");
                    Console.WriteLine();

                    #endregion RetrieveOrganization Message

                }
                //</snippetDiscoveryService1>
            }

            // Catch any service fault exceptions that Microsoft Dynamics CRM throws.
            catch (FaultException<Microsoft.Xrm.Sdk.DiscoveryServiceFault>)
            {
                // You can handle an exception here or pass it back to the calling method.
                throw;
            }
        }
        private static string GetOrganizationName(string crmDiscoveryUrl, Guid orgId)
        {
            IServiceConfiguration<IDiscoveryService> dinfo = ServiceConfigurationFactory.CreateConfiguration<IDiscoveryService>(GetDiscoveryServiceUri(crmDiscoveryUrl));

            var creds = new ClientCredentials();

            DiscoveryServiceProxy dsp = new DiscoveryServiceProxy(dinfo, creds);
            dsp.Authenticate();
            RetrieveOrganizationsRequest orgRequest = new RetrieveOrganizationsRequest();
            RetrieveOrganizationsResponse orgResponse = dsp.Execute(orgRequest) as RetrieveOrganizationsResponse;

            if (orgResponse == null || orgResponse.Details == null || orgResponse.Details.Count == 0)
            {
                throw new Exception("Organization not found");
            }

            return orgResponse.Details.First(o => o.OrganizationId == orgId).UrlName;
        }
        /// <summary>
        /// Get the discovery service proxy based on existing configuration data.
        /// Added new way of getting discovery proxy.
        /// Also preserving old way of getting discovery proxy to support old scenarios.
        /// </summary>
        /// <returns>An instance of DiscoveryServiceProxy</returns>
        private DiscoveryServiceProxy GetDiscoveryProxy()
        {
            IServiceManagement<IDiscoveryService> serviceManagement =
                        ServiceConfigurationFactory.CreateManagement<IDiscoveryService>(
                        config.DiscoveryUri);

            // Get the EndpointType.
            config.EndpointType = serviceManagement.AuthenticationType;

            // Get the logon credentials.
            config.Credentials = GetUserLogonCredentials();

            AuthenticationCredentials authCredentials = new AuthenticationCredentials();

            if (!String.IsNullOrWhiteSpace(config.UserPrincipalName))
            {
                // Try to authenticate the Federated Identity organization with UserPrinicipalName.
                authCredentials.UserPrincipalName = config.UserPrincipalName;

                try
                {
                    AuthenticationCredentials tokenCredentials = serviceManagement.Authenticate(
                        authCredentials);
                    DiscoveryServiceProxy discoveryProxy = new DiscoveryServiceProxy(serviceManagement,
                        tokenCredentials.SecurityTokenResponse);
                    // Checking authentication by invoking some SDK methods.
                    OrganizationDetailCollection orgs = DiscoverOrganizations(discoveryProxy);
                    return discoveryProxy;
                }
                catch (System.ServiceModel.Security.SecurityAccessDeniedException ex)
                {
                    // If authentication failed using current UserPrincipalName,
                    // request UserName and Password to try to authenticate using user credentials.
                    if (ex.Message.Contains("Access is denied."))
                    {
                        config.AuthFailureCount += 1;
                        authCredentials.UserPrincipalName = String.Empty;

                        config.Credentials = GetUserLogonCredentials();
                    }
                    else
                    {
                        throw ex;
                    }
                }
                // You can also catch other exceptions to handle a specific situation in your code, for example,
                //      System.ServiceModel.Security.ExpiredSecurityTokenException
                //      System.ServiceModel.Security.MessageSecurityException
                //      System.ServiceModel.Security.SecurityNegotiationException
            }

            // Resetting credentials in the AuthenicationCredentials.
            if (config.EndpointType != AuthenticationProviderType.ActiveDirectory)
            {
                authCredentials = new AuthenticationCredentials();
                authCredentials.ClientCredentials = config.Credentials;

                if (config.EndpointType == AuthenticationProviderType.LiveId)
                {
                    authCredentials.SupportingCredentials = new AuthenticationCredentials();
                    authCredentials.SupportingCredentials.ClientCredentials = config.DeviceCredentials;
                }
                // Try to authenticate with the user credentials.
                AuthenticationCredentials tokenCredentials1 = serviceManagement.Authenticate(
                    authCredentials);
                return new DiscoveryServiceProxy(serviceManagement,
               tokenCredentials1.SecurityTokenResponse);
            }
            // For an on-premises environment.
            return new DiscoveryServiceProxy(serviceManagement, config.Credentials);
        }
        private string GetCurrentOrganizationName(ServerConnection.Configuration serverConfig)
        {
            using (DiscoveryServiceProxy _discoveryProxy = new DiscoveryServiceProxy(serverConfig.DiscoveryUri,
                        serverConfig.HomeRealmUri, serverConfig.Credentials, serverConfig.DeviceCredentials))
            {
                RetrieveOrganizationsRequest orgsRequest =
                new RetrieveOrganizationsRequest()
                {
                    AccessType = EndpointAccessType.Default,
                    Release = OrganizationRelease.Current
                };
                RetrieveOrganizationsResponse organizations =
                    (RetrieveOrganizationsResponse)_discoveryProxy.Execute(orgsRequest);

                foreach (OrganizationDetail organization in organizations.Details)
                {
                    foreach (var endpoint in organization.Endpoints)
                    {
                        if (endpoint.Value.ToLowerInvariant() == serverConfig.OrganizationUri.ToString().ToLowerInvariant())
                            return organization.FriendlyName;
                    }
                }
            }
            return String.Empty;
        }