Hello,
Every so often I am asked how to go about capturing a contact web form and pushing it’s data into CRM as a Lead for an Internet Facing Deployment(IFD).
What’s different when connecting to the IFD CRM is that we need to make use of the ticketing system in the web service. As you’ll see in the code snippet below I’m generating a ticket that I use to authenticate and apply it to the token for future calls.
// For an IFD site we need to connect to the CrmDiscoveryService and retrieve a ticket // Note the AuthenticationType attached to the Token below. CrmDiscoveryServiceProxy.CrmDiscoveryService disco = new CrmDiscoveryServiceProxy.CrmDiscoveryService(); disco.Url = ConfigurationManager.AppSettings["CrmDiscoveryServiceUrl"].ToString(); // Request a Ticket CrmDiscoveryServiceProxy.RetrieveCrmTicketRequest ticketRequest = new CrmDiscoveryServiceProxy.RetrieveCrmTicketRequest(); ticketRequest.OrganizationName = ConfigurationManager.AppSettings["CrmOrg"].ToString(); ticketRequest.UserId = ConfigurationManager.AppSettings["CrmUsername"].ToString(); ticketRequest.Password = ConfigurationManager.AppSettings["CrmPassword"].ToString(); // Read the Response CrmDiscoveryServiceProxy.RetrieveCrmTicketResponse ticketResponse = (CrmDiscoveryServiceProxy.RetrieveCrmTicketResponse)disco.Execute(ticketRequest); // Generate an Authorization Token CrmServiceProxy.CrmAuthenticationToken token = new CrmServiceProxy.CrmAuthenticationToken(); token.AuthenticationType = 2; // Note the setting of 2 indicates it is IFD, so it will use the ticket. token.OrganizationName = ConfigurationManager.AppSettings["CrmOrg"].ToString(); token.CrmTicket = ticketResponse.CrmTicket; // Apply the ticket to the Token // Service CrmServiceProxy.CrmService crmService = new CrmServiceProxy.CrmService(); crmService.Url = ConfigurationManager.AppSettings["CrmServiceUrl"].ToString(); // Credentials are not required since we have a ticket attached to the token crmService.CrmAuthenticationTokenValue = token; // Create a new Lead CrmServiceProxy.lead webLead = new CrmServiceProxy.lead(); webLead.companyname = webFeedback.Company; webLead.firstname = webFeedback.Firstname; webLead.lastname = webFeedback.Lastname; webLead.telephone1 = webFeedback.Phone; webLead.emailaddress1 = webFeedback.Email; webLead.address1_line1 = webFeedback.Address; webLead.address1_city = webFeedback.City; webLead.address1_stateorprovince = webFeedback.StateProv; webLead.address1_country = webFeedback.Country; webLead.address1_postalcode = webFeedback.PostalCode; webLead.description = webFeedback.Comments; webLead.subject = webFeedback.Regarding; webLead.leadsourcecode = new CrmServiceProxy.Picklist { Value = leadSourceCode }; // Execute Guid leadGuid = crmService.Create(webLead);
And that’s how we connect and push the data into a CRM 4.0 Lead for an IDF deployment.
I would however recommend that a high visibility / volume site push the data into an intermediary database as a stage and set a scheduled task or something similar to push the data into CRM. Having a web form tied directly to your CRM system can open it up to a denial of service attack via the website. At a minimum I would recommend implementing some throttling mechanism for the submission form.
Leave a Reply