getting list of organisations through c#
-
segunda-feira, 20 de agosto de 2012 07:12
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
Todas as Respostas
-
segunda-feira, 20 de agosto de 2012 07:23
Use this
public OrganizationDetailCollection GetOrganizations(String serverURL, String username, String password, String domainname) { IServiceConfiguration<IDiscoveryService> dinfo = ServiceConfigurationFactory.CreateConfiguration<IDiscoveryService>(GetDiscoveryServiceUri(serverURL)); var creds = new ClientCredentials(); creds.Windows.ClientCredential = new System.Net.NetworkCredential(username, password, domainname); DiscoveryServiceProxy dsp = new DiscoveryServiceProxy(dinfo, creds); dsp.Authenticate(); RetrieveOrganizationsRequest orgRequest = new RetrieveOrganizationsRequest(); RetrieveOrganizationsResponse orgResponse = dsp.Execute(orgRequest) as RetrieveOrganizationsResponse; return orgResponse.Details; } private Uri GetDiscoveryServiceUri(string serverName) { string discoSuffix = @"/XRMServices/2011/Discovery.svc"; return new Uri(string.Format("{0}{1}", serverName, discoSuffix)); }Thanks Anil Chelasani http://exploringxrm.wordpress.com
- Marcado como Resposta Mahender PalMVP, Moderator segunda-feira, 20 de agosto de 2012 08:29
-
segunda-feira, 20 de agosto de 2012 07:30
Refer to one of the SDK samples which shows you exactly how to do it: Sample: Authenticate Users with Microsoft Dynamics CRM Web Services
SDK\SampleCode\CS\QuickStartIServiceManagement<IDiscoveryService> serviceManagement = ServiceConfigurationFactory.CreateManagement<IDiscoveryService>( new Uri(_discoveryServiceAddress)); AuthenticationProviderType endpointType = serviceManagement.AuthenticationType; // Set the credentials. AuthenticationCredentials authCredentials = GetCredentials(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]; } }- Sugerido como Resposta Anubhav Bajpai segunda-feira, 20 de agosto de 2012 08:02
- Marcado como Resposta Mahender PalMVP, Moderator segunda-feira, 20 de agosto de 2012 08:29
-
segunda-feira, 20 de agosto de 2012 08:02
Hi,
I would agree with Sweta. Kindly refer the sdk projects provided by Microsoft. This will help you take correct approach to do any CRUD operations related to plugin code(c# or vb) as well as javascripts in Microsoft Supported way. You may download the latest sdk from this link
CRM 2011
http://www.microsoft.com/en-in/download/details.aspx?id=24004
CRM 4.0
http://www.microsoft.com/en-us/download/details.aspx?id=38
Let me know in case you face any difficulty further.
Thanks & Regards,
Anubhav Bajpai
- Sugerido como Resposta Anubhav Bajpai segunda-feira, 20 de agosto de 2012 08:02