locked
getting list of organisations through c# RRS feed

  • Question

  • OrganizationDetailCollection orgs = DiscoverOrganizations(serviceProxy);

    // to get list of organizations run this loop
    for (int n = 0; n < orgs.Count; n++)
     {
          Console.Write("\n({0}) {1} ({2})\t", n + 1, orgs[n].FriendlyName, orgs[n].UrlName);
     }

    public OrganizationDetailCollection DiscoverOrganizations(IDiscoveryService service)
     {
                RetrieveOrganizationsResponse orgResponse = new RetrieveOrganizationsResponse();
                    RetrieveOrganizationsRequest orgRequest = new RetrieveOrganizationsRequest();

                    orgResponse = (RetrieveOrganizationsResponse)service.Execute(orgRequest);

                    return orgResponse.Details;
                
    }

    Hello guys, i got the following code from a kind person to get the list of organisation, but the problem is that, the code is not complete, im unable to figure out how to create the "serviceProxy" in the first line of code. can any one tell me how to create the IDiscoveryService object for the above program

    Monday, August 20, 2012 7:13 AM

Answers

All replies

  • Hi Syed,

    It is a object of proxy which let you to perform discovery operations on CRM instance.

    Please refer , http://crm2011corner.blogspot.in/2012/01/creating-service-proxy-and-context-in.html


    Thanks and regards,
    Hiren Solanki.
    Please vote or mark as a answer if it helped you.

    Monday, August 20, 2012 7:25 AM
  • hi,

    check this

    // get list of Organizations from CRM
    OrganizationDetailCollection allOrgs=RetrieveOrganizations("username","password","crmUrl");
    
    
     public static OrganizationDetailCollection RetrieveOrganizations(string UserName, string Password, string Domain, string URL)
            {
                Dictionary<string, string> lstOrg = new Dictionary<string, string>();
                DiscoveryServiceProxy _serviceProxy;
                // The using statement assures that the service proxy will be properly disposed.
                ClientCredentials clientCredentials = new ClientCredentials();
                clientCredentials.UserName.UserName = Domain + "\\" + UserName;
                clientCredentials.UserName.Password = Password;
    
                using (_serviceProxy = new DiscoveryServiceProxy(new Uri(URL + "/XRMServices/2011/Discovery.svc"), null, clientCredentials, null))
                {
    
                    // Retrieve details about all organizations discoverable via the
                    // Discovery service.
                    Microsoft.Xrm.Sdk.Discovery.RetrieveOrganizationsRequest orgsRequest = new Microsoft.Xrm.Sdk.Discovery.RetrieveOrganizationsRequest()
                    {
                        AccessType = EndpointAccessType.Default,
                        Release = OrganizationRelease.Current
                    };
                    Microsoft.Xrm.Sdk.Discovery.RetrieveOrganizationsResponse organizations =
                        (Microsoft.Xrm.Sdk.Discovery.RetrieveOrganizationsResponse)_serviceProxy.Execute(orgsRequest);
                    return organizations.Details;
                }
            }
        }


    Please don't forget to Vote and marked as answer If this post answers your question or was helpful, please click "Mark As Answer" on the post and "Mark as Helpful" Be wise

    • Proposed as answer by anwar.noori Thursday, August 23, 2012 8:16 AM
    Wednesday, August 22, 2012 6:17 AM
    • Proposed as answer by Anil_Ch Wednesday, August 22, 2012 8:27 AM
    • Marked as answer by SyedHaroon Wednesday, August 22, 2012 10:13 AM
    Wednesday, August 22, 2012 8:27 AM