By looking at your code, you are not using username and password
Change below lines:
var credentials = new ClientCredentials();
credentials.UserName.UserName =ConfigurationManager.AppSettings["username"].toString();
credentials.UserName.Password =ConfigurationManager.AppSettings["password"].toString();
try the following: Default Credentials are used,using Windows Authentication
ClientCredentials Credentials = new ClientCredentials();
Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
// This URL needs to be updated to match the server name and organization for the environment.
Uri OrganizationUri = new Uri("http://XXXXX/XRMServices/2011/Organization.svc");
Uri HomeRealmUri = null;
using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, null))
{
IOrganizationService service = (IOrganizationService)serviceProxy;
}
source
share