used 9.0 version of SDK
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Tooling.Connector;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Net;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Tooling.Connector;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Net;
namespace OnlineLogin
{
class OnlineLoginSamples
{
private static IOrganizationService _orgService;
static void Main(string[] args)
{
//Get CRM Configuration Details
String connectionString = GetServiceConfiguration();
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
CrmServiceClient conn = new CrmServiceClient(connectionString);
// Cast the proxy client to the IOrganizationService interface.
_orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;
Entity account = new Entity(“account”);
account[“name”] = “Dummy_Account_Test1”;
System.Guid _accountId = _orgService.Create(account);
}
private static String GetServiceConfiguration()
{
// Get available connection strings from app.config.
int count = ConfigurationManager.ConnectionStrings.Count;
{
class OnlineLoginSamples
{
private static IOrganizationService _orgService;
static void Main(string[] args)
{
//Get CRM Configuration Details
String connectionString = GetServiceConfiguration();
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
CrmServiceClient conn = new CrmServiceClient(connectionString);
// Cast the proxy client to the IOrganizationService interface.
_orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;
Entity account = new Entity(“account”);
account[“name”] = “Dummy_Account_Test1”;
System.Guid _accountId = _orgService.Create(account);
}
private static String GetServiceConfiguration()
{
// Get available connection strings from app.config.
int count = ConfigurationManager.ConnectionStrings.Count;
// Create a filter list of connection strings so that we have a list of valid
// connection strings for Microsoft Dynamics CRM only.
List<KeyValuePair<String, String>> filteredConnectionStrings =
new List<KeyValuePair<String, String>>();
for (int a = 0; a < count; a++)
{
if (isValidConnectionString(ConfigurationManager.ConnectionStrings[a].ConnectionString))
filteredConnectionStrings.Add
(new KeyValuePair<string, string>
(ConfigurationManager.ConnectionStrings[a].Name,
ConfigurationManager.ConnectionStrings[a].ConnectionString));
}
// connection strings for Microsoft Dynamics CRM only.
List<KeyValuePair<String, String>> filteredConnectionStrings =
new List<KeyValuePair<String, String>>();
for (int a = 0; a < count; a++)
{
if (isValidConnectionString(ConfigurationManager.ConnectionStrings[a].ConnectionString))
filteredConnectionStrings.Add
(new KeyValuePair<string, string>
(ConfigurationManager.ConnectionStrings[a].Name,
ConfigurationManager.ConnectionStrings[a].ConnectionString));
}
// No valid connections strings found. Write out and error message.
if (filteredConnectionStrings.Count == 0)
{
Console.WriteLine(“An app.config file containing at least one valid Microsoft Dynamics CRM ” +
“connection string configuration must exist in the run-time folder.”);
Console.WriteLine(“\nThere are several commented out example connection strings in ” +
“the provided app.config file. Uncomment one of them and modify the string according ” +
“to your Microsoft Dynamics CRM installation. Then re-run the sample.”);
return null;
}
if (filteredConnectionStrings.Count == 0)
{
Console.WriteLine(“An app.config file containing at least one valid Microsoft Dynamics CRM ” +
“connection string configuration must exist in the run-time folder.”);
Console.WriteLine(“\nThere are several commented out example connection strings in ” +
“the provided app.config file. Uncomment one of them and modify the string according ” +
“to your Microsoft Dynamics CRM installation. Then re-run the sample.”);
return null;
}
// If one valid connection string is found, use that.
if (filteredConnectionStrings.Count == 1)
{
return filteredConnectionStrings[0].Value;
}
if (filteredConnectionStrings.Count == 1)
{
return filteredConnectionStrings[0].Value;
}
// If more than one valid connection string is found, let the user decide which to use.
if (filteredConnectionStrings.Count > 1)
{
Console.WriteLine(“The following connections are available:”);
Console.WriteLine(“————————————————“);
if (filteredConnectionStrings.Count > 1)
{
Console.WriteLine(“The following connections are available:”);
Console.WriteLine(“————————————————“);
for (int i = 0; i < filteredConnectionStrings.Count; i++) { Console.Write(“\n({0}) {1}\t”, i + 1, filteredConnectionStrings[i].Key); } Console.WriteLine(); Console.Write(“\nType the number of the connection to use (1-{0}) [{0}] : “, filteredConnectionStrings.Count); String input = Console.ReadLine(); int configNumber; if (input == String.Empty) input = filteredConnectionStrings.Count.ToString(); if (!Int32.TryParse(input, out configNumber) || configNumber > count ||
configNumber == 0)
{
Console.WriteLine(“Option not valid.”);
return null;
}
configNumber == 0)
{
Console.WriteLine(“Option not valid.”);
return null;
}
return filteredConnectionStrings[configNumber – 1].Value;
}
return null;
return null;
}
///
/// Verifies if a connection string is valid for Microsoft Dynamics CRM.
///
/// Verifies if a connection string is valid for Microsoft Dynamics CRM.
///
/// True for a valid string, otherwise False.
private static Boolean isValidConnectionString(String connectionString)
{
// At a minimum, a connection string must contain one of these arguments.
if (connectionString.Contains(“Url=”) ||
connectionString.Contains(“Server=”) ||
connectionString.Contains(“ServiceUri=”))
return true;
private static Boolean isValidConnectionString(String connectionString)
{
// At a minimum, a connection string must contain one of these arguments.
if (connectionString.Contains(“Url=”) ||
connectionString.Contains(“Server=”) ||
connectionString.Contains(“ServiceUri=”))
return true;
return false;
}
}
}
}
}
}
=====================================================
Web.Config
=====================================================
=====================================================
<?xml version=”1.0″ encoding=”utf-8″?>
<configuration>
<connectionStrings>
<add name=”Server=CRM Online, organization=dasgoutam, user=goutam” connectionString=”Url=https://dasgoutam.crm8.dynamics.com; Username=dasgoutam@xxxx.onmicrosoft.com; Password=xxxx; authtype=Office365″/>
</connectionStrings>
<startup>
<supportedRuntime version=”v4.0″ sku=”.NETFramework,Version=v4.6.1″/>
</startup>
<system.diagnostics>
<trace autoflush=”true”/>
<sources>
<source name=”Microsoft.Xrm.Tooling.Connector.CrmServiceClient” switchName=”Microsoft.Xrm.Tooling.Connector.CrmServiceClient” switchType=”System.Diagnostics.SourceSwitch”>
<listeners>
<add name=”console” type=”System.Diagnostics.ConsoleTraceListener”/>
<add name=”fileListener”/>
</listeners>
</source>
<source name=”Microsoft.Xrm.Tooling.CrmConnectControl” switchName=”Microsoft.Xrm.Tooling.CrmConnectControl” switchType=”System.Diagnostics.SourceSwitch”>
<listeners>
<add name=”console” type=”System.Diagnostics.ConsoleTraceListener”/>
<add name=”fileListener”/>
</listeners>
</source>
<source name=”CrmSvcUtil” switchName=”CrmSvcUtil” switchType=”System.Diagnostics.SourceSwitch”>
<listeners>
<add name=”console” type=”System.Diagnostics.ConsoleTraceListener”/>
<add name=”fileListener”/>
</listeners>
</source>
</sources>
<switches>
<configuration>
<connectionStrings>
<add name=”Server=CRM Online, organization=dasgoutam, user=goutam” connectionString=”Url=https://dasgoutam.crm8.dynamics.com; Username=dasgoutam@xxxx.onmicrosoft.com; Password=xxxx; authtype=Office365″/>
</connectionStrings>
<startup>
<supportedRuntime version=”v4.0″ sku=”.NETFramework,Version=v4.6.1″/>
</startup>
<system.diagnostics>
<trace autoflush=”true”/>
<sources>
<source name=”Microsoft.Xrm.Tooling.Connector.CrmServiceClient” switchName=”Microsoft.Xrm.Tooling.Connector.CrmServiceClient” switchType=”System.Diagnostics.SourceSwitch”>
<listeners>
<add name=”console” type=”System.Diagnostics.ConsoleTraceListener”/>
<add name=”fileListener”/>
</listeners>
</source>
<source name=”Microsoft.Xrm.Tooling.CrmConnectControl” switchName=”Microsoft.Xrm.Tooling.CrmConnectControl” switchType=”System.Diagnostics.SourceSwitch”>
<listeners>
<add name=”console” type=”System.Diagnostics.ConsoleTraceListener”/>
<add name=”fileListener”/>
</listeners>
</source>
<source name=”CrmSvcUtil” switchName=”CrmSvcUtil” switchType=”System.Diagnostics.SourceSwitch”>
<listeners>
<add name=”console” type=”System.Diagnostics.ConsoleTraceListener”/>
<add name=”fileListener”/>
</listeners>
</source>
</sources>
<switches>
<!–Possible values for switches: Off, Error, Warning, Information, Verbose
Verbose: includes Error, Warning, Info, Trace levels
Information: includes Error, Warning, Info levels
Warning: includes Error, Warning levels
Error: includes Error level–>
Verbose: includes Error, Warning, Info, Trace levels
Information: includes Error, Warning, Info levels
Warning: includes Error, Warning levels
Error: includes Error level–>
<add name=”Microsoft.Xrm.Tooling.CrmConnectControl” value=”Off”/>
<add name=”Microsoft.Xrm.Tooling.Connector.CrmServiceClient” value=”Error”/>
<add name=”CrmSvcUtil” value=”Off”/>
</switches>
<add name=”Microsoft.Xrm.Tooling.Connector.CrmServiceClient” value=”Error”/>
<add name=”CrmSvcUtil” value=”Off”/>
</switches>
<sharedListeners>
<add name=”fileListener” type=”System.Diagnostics.TextWriterTraceListener” initializeData=”CrmSvcUtil.log”/>
</sharedListeners>
<add name=”fileListener” type=”System.Diagnostics.TextWriterTraceListener” initializeData=”CrmSvcUtil.log”/>
</sharedListeners>
</system.diagnostics>
<runtime>
<assemblyBinding xmlns=”urn:schemas-microsoft-com:asm.v1″>
<dependentAssembly>
<assemblyIdentity name=”Microsoft.Xrm.Sdk” publicKeyToken=”31bf3856ad364e35″ culture=”neutral”/>
<bindingRedirect oldVersion=”0.0.0.0-9.0.0.0″ newVersion=”9.0.0.0″/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name=”Microsoft.Xrm.Sdk.Deployment” publicKeyToken=”31bf3856ad364e35″ culture=”neutral”/>
<bindingRedirect oldVersion=”0.0.0.0-7.0.0.0″ newVersion=”8.0.0.0″/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name=”Microsoft.ServiceBus” publicKeyToken=”31bf3856ad364e35″ culture=”neutral”/>
<bindingRedirect oldVersion=”0.0.0.0-2.4.0.0″ newVersion=”2.4.0.0″/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name=”Microsoft.Crm.Sdk.Proxy” publicKeyToken=”31bf3856ad364e35″ culture=”neutral”/>
<bindingRedirect oldVersion=”0.0.0.0-9.0.0.0″ newVersion=”9.0.0.0″/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name=”Microsoft.IdentityModel.Clients.ActiveDirectory” publicKeyToken=”31bf3856ad364e35″ culture=”neutral”/>
<bindingRedirect oldVersion=”0.0.0.0-3.19.2.6005″ newVersion=”3.19.2.6005″/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
<runtime>
<assemblyBinding xmlns=”urn:schemas-microsoft-com:asm.v1″>
<dependentAssembly>
<assemblyIdentity name=”Microsoft.Xrm.Sdk” publicKeyToken=”31bf3856ad364e35″ culture=”neutral”/>
<bindingRedirect oldVersion=”0.0.0.0-9.0.0.0″ newVersion=”9.0.0.0″/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name=”Microsoft.Xrm.Sdk.Deployment” publicKeyToken=”31bf3856ad364e35″ culture=”neutral”/>
<bindingRedirect oldVersion=”0.0.0.0-7.0.0.0″ newVersion=”8.0.0.0″/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name=”Microsoft.ServiceBus” publicKeyToken=”31bf3856ad364e35″ culture=”neutral”/>
<bindingRedirect oldVersion=”0.0.0.0-2.4.0.0″ newVersion=”2.4.0.0″/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name=”Microsoft.Crm.Sdk.Proxy” publicKeyToken=”31bf3856ad364e35″ culture=”neutral”/>
<bindingRedirect oldVersion=”0.0.0.0-9.0.0.0″ newVersion=”9.0.0.0″/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name=”Microsoft.IdentityModel.Clients.ActiveDirectory” publicKeyToken=”31bf3856ad364e35″ culture=”neutral”/>
<bindingRedirect oldVersion=”0.0.0.0-3.19.2.6005″ newVersion=”3.19.2.6005″/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
No comments:
Post a Comment