Hello Team,
After setting CRM outlook client to offline I am trying to create an account entity using c# code. To create an entity in offline mode I am passing all values but still getting "The user authentication failed!" exception:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Client;
using Microsoft.Xrm.Client.Configuration;
using Microsoft.Xrm.Client.Services;
using System.ServiceModel.Description;
using System.ServiceModel;
using System.Net;
namespace Offline
{
public class CRMConnector
{
#region Class Variables
OrganizationServiceProxy service;
OrganizationServiceContext serviceContext;
public string sUserName = string.Empty;
public string sDomain = string.Empty;
public string sPassword = string.Empty;
public Uri OrgUri;
#endregion
public CRMConnector()
{
sUserName = oCryptHelper.Decrypt(Properties.Settings.Default.UserName.ToString());
sDomain = oCryptHelper.Decrypt(Properties.Settings.Default.Domain.ToString());
sPassword = oCryptHelper.Decrypt(Properties.Settings.Default.Password.ToString());
OrgUri = new Uri("http://localhost:2525/XRMServices/2011/Organization.svc");
}
internal OrganizationServiceContext Connector()
{
CRMConnector crmconn = new CRMConnector();
ClientCredentials credentials = new ClientCredentials();
credentials.Windows.ClientCredential = new System.Net.NetworkCredential(crmconn.sUserName, crmconn.sPassword, crmconn.sDomain);
//credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
using (service = new OrganizationServiceProxy(crmconn.OrgUri, null, credentials, null))
{
service.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
OrganizationServiceContext orgIntitialContext = new OrganizationServiceContext(service);
OrganizationServiceContext orgContext = new OrganizationServiceContext(service);
Entity account = new Entity("account");
Guid accountId = service.Create(account);
return orgContext;
}
}
}
}
If I try to access the online organisation service same manner then I am not getting any issue.
Even I can access the http://localhost:2525/XRMServices/2011/Organization.svc in browser.
Can you please suggest me why exactly I am getting that error.
Thanks a lot.