I have created a web form in Visual Studio that when I run locally works great. It takes the input fields and creates a contact in the CRM. I can use the html to put the web form up on a website but then that is where I am stuck and can't seem to find any more information. Where am I connecting the server side code (shown below) so that it captures the input values from the form once published on our website.
I followed this link here: http://blogs.msdn.com/b/crminthefield/archive/2011/05/18/how-to-create-a-simple-webpage-leveraging-the-crm-2011-iorganizationservice-web-service.aspx to create this. I also copied the html into a web resource and the form successfully
shows up but again the code to actually create the contact isn't connecting so I'm not sure how to do that.
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.ServiceModel.Description; using Microsoft.Xrm.Sdk.Client; using System.Net; using Microsoft.Xrm.Sdk; namespace CRMContactDataEntry { public partial class WebForm1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { //Authenticate using credentials of the logged in user; ClientCredentials Credentials = new ClientCredentials(); Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials; //This URL needs to be updated to match the servername and Organization for the environment. Uri OrganizationUri = new Uri("http://server/name/XRMServices/2011/Organization.svc"); Uri HomeRealmUri = null; //OrganizationServiceProxy serviceProxy; using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, null)) { IOrganizationService service = (IOrganizationService)serviceProxy; //Instantiate the contact object and populate the attributes. Entity contact = new Entity("contact"); contact["firstname"] = txtFirstName.Text.ToString(); contact["lastname"] = txtLastName.Text.ToString(); contact["emailaddress1"] = txtEmailAddress.Text.ToString(); contact["telephone1"] = txtPhoneNumber.Text.ToString(); Guid newContactId = service.Create(contact); //This code will clear the textboxes after the contact is created. txtFirstName.Text = ""; txtLastName.Text = ""; txtEmailAddress.Text = ""; txtPhoneNumber.Text = ""; } } } }
Thanks for any help!
-Trevor