Here is the code. I'm conecting successfully to CRM but when it comes to create new entry
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel.Description;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Sdk;
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Query;
namespace InfoRequest.Services
{
public class CRMInfoRequestService
{
private IOrganizationService CRMService() {
System.Configuration.Configuration rootWebConfig1 = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(null);
string strOrganizationUri = System.Configuration.ConfigurationManager.AppSettings["strOrganizationUri"];
string strUserName = System.Configuration.ConfigurationManager.AppSettings["username"];
string strPassword = System.Configuration.ConfigurationManager.AppSettings["password"];
var organizationUriIFD = new Uri(strOrganizationUri);
var credentials = new ClientCredentials();
credentials.UserName.UserName = strUserName;
credentials.UserName.Password = strPassword;
IServiceConfiguration<IOrganizationService> config = ServiceConfigurationFactory.CreateConfiguration<IOrganizationService>(organizationUriIFD);
IOrganizationService service;
using (var serviceProxy = new OrganizationServiceProxy(config, credentials))
{
// This statement is required to enable early-bound type support.
serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
service = serviceProxy;
var who = new WhoAmIRequest();
//retreive user data from the server.
var whoResponse = (WhoAmIResponse)service.Execute(who);
System.Diagnostics.Debug.WriteLine(whoResponse.UserId);
return service;
}
// Get the ID's of the current user and business unit.
//in case of failure
return null;
}
public bool submitInoRequestFormDataToCRM() {
var service = CRMService();
if (service == null) return false;
Entity account = new Entity("contact");
account.Attributes["firstname"] = this.first;
account.Attributes["lastname"] = "Test3";
account.Attributes["datatel_prospectsourceid"] = "Beacardinal Website";
account.Attributes["preferredcontactmethodcode"] = new OptionSetValue(2);
// account.Attributes["address1_telephone1"] = "3333333333";
try
{
service.Create(account);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
return false;
}
Console.WriteLine("Done");
return true;
}
}
}