This documentation is archived and is not being maintained.

RetrieveCrmTicket Message (DiscoveryService)

Forefront
banner art

[Applies to: Microsoft Dynamics CRM 4.0]

Find the latest SDK documentation: CRM 2015 SDK

Works for all deployment typesWorks online only

Retrieves an authentication ticket from the CrmDiscoveryService Web service.

The relevant classes are specified in the following table.

TypeClass
RequestRetrieveCrmTicketRequest
ResponseRetrieveCrmTicketResponse

Remarks

The ticket is used in the authentication process for Microsoft Dynamics CRM Online or Internet-facing deployments (IFDs).

Example

The following code samples show how to retrieve a ticket for use in Microsoft Dynamics CRM Online authentication.

[C#]
// Login information for authentication through the Passport service.
string username = "someone@microsoft.com";
string password = "password";
string partner = "crm.dynamics.com";
string environment = "Production";

// Set the name and TCP port of the server hosting Microsoft Dynamics CRM Online.
string hostname = "dev.crm.dynamics.com";

// Set the friendly name of the target organization.
string organization = "AdventureWorksCycle";
        
// Create the discovery service
CrmDiscoveryService discoveryService = new CrmDiscoveryService();
discoveryService.Url = String.Format("https://{0}/MSCRMServices/2007/{1}/CrmDiscoveryService.asmx", hostname, "Passport");

// Retrieve a policy.
RetrievePolicyRequest policyRequest = new RetrievePolicyRequest();
RetrievePolicyResponse policyResponse = (RetrievePolicyResponse)discoveryService.Execute(policyRequest);

// Retrieve a Passport ticket from the Passport service.
LogonManager lm = new LogonManager();
string passportTicket = lm.Logon(username, password, partner, policyResponse.Policy, environment);

// Retrieve a list of organizations that the logged on user is a member of.
RetrieveOrganizationsRequest orgRequest = new RetrieveOrganizationsRequest();
orgRequest.PassportTicket = passportTicket;
RetrieveOrganizationsResponse orgResponse =
    (RetrieveOrganizationsResponse)discoveryService.Execute(orgRequest);
// Locate the target organization name using the organization friendly name.
String orgUniqueName = String.Empty;
OrganizationDetail orgInfo = null;
foreach (OrganizationDetail orgDetail in orgResponse.OrganizationDetails)
{
    if (orgDetail.FriendlyName.Equals(orgFriendlyName))
    {
        orgInfo = orgDetail;
        orgUniqueName = orgInfo.OrganizationName;
        break;
    }
}
// Retrieve the CrmTicket.
RetrieveCrmTicketRequest crmTicketRequest = new RetrieveCrmTicketRequest();
                crmTicketRequest.OrganizationName = orgUniqueName;
crmTicketRequest.PassportTicket = passportTicket;

// Retrieve a CrmTicket from the Discovery Web service.
RetrieveCrmTicketResponse crmTicketResponse = (RetrieveCrmTicketResponse)discoveryService.Execute(crmTicketRequest);
[Visual Basic .NET]
' Login information for authentication through the Passport service.
Dim username As String = "someone@microsoft.com"
Dim password As String = "password"
Dim partner As String = "crm.dynamics.com"
Dim environment As String = "Production"

' Set the name and TCP port of the server hosting Microsoft Dynamics CRM Online.
Dim hostname As String = "dev.crm.dynamics.com"

' Set the friendly name of the target organization.
' SDK: string orgFriendlyName = "AdventureWorksCycle"

' Create the discovery service
Dim discoveryService As New CrmDiscoveryService()
discoveryService.Url = String.Format("https://{0}/MSCRMServices/2007/{1}/CrmDiscoveryService.asmx", hostname, "Passport")

' Retrieve a policy.
Dim policyRequest As New RetrievePolicyRequest()
Dim policyResponse As RetrievePolicyResponse = CType(discoveryService.Execute(policyRequest), RetrievePolicyResponse)

' Retrieve a Passport ticket from the Passport service.
Dim lm As New LogonManager()
Dim passportTicket As String = lm.Logon(username, password, partner, policyResponse.Policy, environment)

' Retrieve a list of organizations that the logged on user is a member of.
Dim orgRequest As New RetrieveOrganizationsRequest()
orgRequest.PassportTicket = passportTicket
Dim orgResponse As RetrieveOrganizationsResponse = CType(discoveryService.Execute(orgRequest), RetrieveOrganizationsResponse)
' Locate the target organization name using the organization friendly name.
Dim orgUniqueName As String = String.Empty
Dim orgInfo As OrganizationDetail = Nothing
For Each orgDetail As OrganizationDetail In orgResponse.OrganizationDetails
    If orgDetail.FriendlyName.Equals(orgFriendlyName) Then
        orgInfo = orgDetail
        orgUniqueName = orgInfo.OrganizationName
        Exit For
    End If
Next orgDetail
' Retrieve the CrmTicket.
Dim crmTicketRequest As New RetrieveCrmTicketRequest()
crmTicketRequest.OrganizationName = orgUniqueName
crmTicketRequest.PassportTicket = passportTicket

' Retrieve a CrmTicket from the Discovery Web service.
Dim crmTicketResponse As RetrieveCrmTicketResponse = CType(discoveryService.Execute(crmTicketRequest), RetrieveCrmTicketResponse)

See Also

Concepts

Reference


© 2010 Microsoft Corporation. All rights reserved.


Show: