Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Get orgs from disco service
- CrmDiscoveryService disco = new CrmDiscoveryService();
- disco.Url = "https://notthereal.crmurl.com/MSCRMServices/2007/SPLA/CrmDiscoveryService.asmx";
- RetrieveOrganizationsRequest orgRequest = new RetrieveOrganizationsRequest();
- orgRequest.UserId = @"mydomainmyuser";
- orgRequest.Password = "mypassword";
- RetrieveOrganizationsResponse orgResponse =
- (RetrieveOrganizationsResponse)disco.Execute(orgRequest);
- // Find the test org
- OrganizationDetail orgInfo = null;
- foreach (OrganizationDetail orgdetail in orgResponse.OrganizationDetails)
- {
- if (orgdetail.OrganizationName.Equals("TestOrganization"))
- {
- orgInfo = orgdetail;
- break;
- }
- }
- if (orgInfo == null)
- {
- throw new Exception("The specified organization was not found.");
- }
- // Get a CRM ticket
- RetrieveCrmTicketRequest ticketRequest = new RetrieveCrmTicketRequest();
- ticketRequest.OrganizationName = orgInfo.OrganizationName;
- ticketRequest.UserId = @"mydomainmyuser";
- ticketRequest.Password = "mypassword";
- RetrieveCrmTicketResponse ticketResponse
- = (RetrieveCrmTicketResponse)disco.Execute(ticketRequest);
- // Create an authorization token
- CrmAuthenticationToken sdktoken = new CrmAuthenticationToken();
- sdktoken.AuthenticationType = 2;
- sdktoken.OrganizationName = orgInfo.OrganizationName;
- sdktoken.CrmTicket = ticketResponse.CrmTicket;
- CrmService service = new CrmService();
- service.CrmAuthenticationTokenValue = sdktoken;
- service.Url = orgInfo.CrmServiceUrl;
- // Retrieve the accounts
- RetrieveMultipleRequest request = new RetrieveMultipleRequest();
- request.Query = new QueryExpression("account");
- // 401 EXCEPTION WHEN EXECUTING NEXT LINE
- var response = (RetrieveMultipleResponse)service.Execute(request);
- // Show the count of accounts
- Console.WriteLine(response.BusinessEntityCollection.BusinessEntities.Count);
- CrmAuthenticationToken sdktoken = new CrmAuthenticationToken();
- sdktoken.AuthenticationType = 2;
- The AuthenticationType class exposes the following members.
- Field Value Description
- AD 0 Specifies Active Directory authentication.
- Passport 1 Specifies Windows Live ID authentication.
- Spla 2 Specifies Internet-Facing Deployment authentication (formerly known as SPLA).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement