To logging in to CRM 365 through c# we need to use below code.
For this purpose i have created a method.
After adding the reference libraries in the project used below code to login.
public static void ConnectToMSCRM(string UserName, string Password, string SoapOrgServiceUri)
{
try
{
IOrganizationService _service;
ClientCredentials credentials = new ClientCredentials();
credentials.UserName.UserName = UserName;
credentials.UserName.Password = Password;
Uri serviceUri = new Uri(SoapOrgServiceUri);
OrganizationServiceProxy proxy = new OrganizationServiceProxy(serviceUri, null, credentials, null);
proxy.EnableProxyTypes();
_service = (IOrganizationService)proxy;
}
catch (Exception ex)
{
MessageBox.Show("Connection can not be established with crm.", "Info", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
Now call this method with the following parameter.
ConnectToMSCRM("YourUserName","YourPassword","YourCrmWebUrl")
You can find the web url under "Customization" tab "Developer Resources".
Copy the "Organization Service" url. Which would be your url to use in the code.
For this purpose i have created a method.
After adding the reference libraries in the project used below code to login.
public static void ConnectToMSCRM(string UserName, string Password, string SoapOrgServiceUri)
{
try
{
IOrganizationService _service;
ClientCredentials credentials = new ClientCredentials();
credentials.UserName.UserName = UserName;
credentials.UserName.Password = Password;
Uri serviceUri = new Uri(SoapOrgServiceUri);
OrganizationServiceProxy proxy = new OrganizationServiceProxy(serviceUri, null, credentials, null);
proxy.EnableProxyTypes();
_service = (IOrganizationService)proxy;
}
catch (Exception ex)
{
MessageBox.Show("Connection can not be established with crm.", "Info", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
Now call this method with the following parameter.
ConnectToMSCRM("YourUserName","YourPassword","YourCrmWebUrl")
You can find the web url under "Customization" tab "Developer Resources".
Copy the "Organization Service" url. Which would be your url to use in the code.
Comments
Post a Comment