|
19.05.2011, 02:11 | #1 |
Участник
|
crminthefield: How to Create a Simple Webpage Leveraging The CRM 2011 IOrganizationService Web Service
Источник: http://blogs.msdn.com/b/crminthefiel...b-service.aspx
============== Recently I have received a lot of questions about how to get started in developing against CRM 2011. The SDK provides many different examples and provides helper classes which can be reused to save some time when developing applications. For someone very new at developing for CRM the robust SDK examples may be more than they want to start with. Below I have provided steps to create a simple webpage that users the IOrganizationService Web Service to create contacts in CRM. This is a simplified solution that does not use any of the helper classes provided in the SDK and will only support AD authentication. The user that runs this webpage will need to be a CRM user in order for the example to work. Scenario: The CRM users need the ability to add contacts into the CRM system without using the main CRM application. They would like a simple data entry website with minimal fields. To accomplish this we will develop an asp.net website that connects to the CRM 2011 platform using the IOrganizationService Web Service. The custom website will allow the user to specify the contact name, email address, and phone number. When the submit button is pressed on the page it will automatically create the contact record within CRM. Requirements:
Create a Custom Web Site Step by Step 1. Create a new Web Site: a. Open Visual Studio 2010 to create a new web site.2. Add a Title and Field Names to the Default.aspx page. a. Within Solution Explorer right click on the Default.aspx page and choose View Designer.3. Add four Textbox’s and a Button to the aspx page. a. Click View|Toolbox. When the toolbox window opens click the pin icon to keep the window open.4. Add code to the Button’s Click Event. a. Double-Click the Button control on the Default.aspx page. This will take you to the Default.aspx.cs file where we can see the Button1_Click method.protectedvoid Button1_Click(object sender, EventArgs e) { //Authenticate using credentials of the logged in user; [COLOR= ]ClientCredentials[/COLOR] Credentials = newClientCredentials(); Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials; //This URL needs to be updated to match the servername and Organization for the environment. Uri OrganizationUri = newUri("http:////XRMServices/2011/Organization.svc"); Uri HomeRealmUri = null; //OrganizationServiceProxy serviceProxy; using (OrganizationServiceProxy serviceProxy = newOrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, null)) { IOrganizationService service = (IOrganizationService)serviceProxy; //Instantiate the contact object and populate the attributes. Entity contact = newEntity("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 = ""; } } 5. Add the Microsoft.Xrm.Sdk and Microsoft.crm.sdk.proxy assemblies as references. a. Locate the Solution Explorer, right-click the ProjectName and choose Add Reference.using System.ServiceModel.Description; using Microsoft.Xrm.Sdk.Client; using System.Net; using Microsoft.Xrm.Sdk; e. The completed code should look similar to the following.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; publicpartialclass_Default : System.Web.UI.Page { protectedvoid Page_Load(object sender, EventArgs e) { } protectedvoid Button1_Click(object sender, EventArgs e) { ClientCredentials Credentials = newClientCredentials(); Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials; //This URL needs to be updated to match the servername and Organization for the environment. Uri OrganizationUri = newUri("http:////XRMServices/2011/Organization.svc"); Uri HomeRealmUri = null; //OrganizationServiceProxy serviceProxy; using (OrganizationServiceProxy serviceProxy = newOrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, null)) { IOrganizationService service = (IOrganizationService)serviceProxy; //Instantiate the contact object and populate the attributes. Entity contact = newEntity("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 = ""; } } } 6. Compile and Run the Custom Page. a. Click Build|Build Solution. If everything is correct you will see it say Build Succeeded at the bottom of the Visual Studio Window. Источник: http://blogs.msdn.com/b/crminthefiel...b-service.aspx
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору. |
|
|
Опции темы | Поиск в этой теме |
Опции просмотра | |
|