locked
MSCRM 2013 online console application service intialization code RRS feed

  • Question

  • Hi

    CRM 2013 online application service intilization  for console application code?


    Rammohan

    Thursday, May 29, 2014 6:14 AM

All replies

  • Hello,

    Check this article.


    Dynamics CRM MVP/ Technical Evangelist at SlickData LLC
    My blog

    Thursday, May 29, 2014 6:22 AM
    Moderator
  • Hi,

    Try this code:

    public IOrganizationService getOrganisationService()
    {
    	IOrganizationService orgService = null;
    
    	try
    	{
    		ClientCredentials credentials = new ClientCredentials();
    		credentials.UserName.UserName = ConfigurationManager.AppSettings["userName"];
    		credentials.UserName.Password = ConfigurationManager.AppSettings["password"];
    
    		Uri serviceUri = new Uri(string.Format("https://{0}.api.crm5.dynamics.com/XRMServices/2011/Organization.svc",ConfigurationManager.AppSettings["orgName"]));
    
    		OrganizationServiceProxy orgServiceProxy = new OrganizationServiceProxy(serviceUri, null, credentials, null);
    		orgServiceProxy.EnableProxyTypes();
    
    		orgService = (IOrganizationService)orgServiceProxy;
    	}
    	catch (FaultException<OrganizationServiceFault> ex)
    	{
    		Console.WriteLine("The application terminated with an error.");
    		Console.WriteLine("Timestamp: {0}", ex.Detail.Timestamp);
    		Console.WriteLine("Code: {0}", ex.Detail.ErrorCode);
    		Console.WriteLine("Message: {0}", ex.Detail.Message);
    		Console.WriteLine("Inner Fault: {0}", null == ex.Detail.InnerFault ? "No Inner Fault" : "Has Inner Fault");
    	}
    	catch (TimeoutException ex)
    	{
    		Console.WriteLine("The application terminated with an error.");
    		Console.WriteLine("Message: {0}", ex.Message);
    		Console.WriteLine("Stack Trace: {0}", ex.StackTrace);
    		Console.WriteLine("Inner Fault: {0}", null == ex.InnerException.Message ? "No Inner Fault" : ex.InnerException.Message);
    	}
    	catch (Exception ex)
    	{
    		Console.WriteLine("The application terminated with an error.");
    		Console.WriteLine(ex.Message);
    
    		// Display the details of the inner exception.
    		if (ex.InnerException != null)
    		{
    			Console.WriteLine(ex.InnerException.Message);
    
    			FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault> fe = ex.InnerException as FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault>;
    
    			if (fe != null)
    			{
    				Console.WriteLine("Timestamp: {0}", fe.Detail.Timestamp);
    				Console.WriteLine("Code: {0}", fe.Detail.ErrorCode);
    				Console.WriteLine("Message: {0}", fe.Detail.Message);
    				Console.WriteLine("Trace: {0}", fe.Detail.TraceText);
    				Console.WriteLine("Inner Fault: {0}", null == fe.Detail.InnerFault ? "No Inner Fault" : "Has Inner Fault");
    			}
    		}
    	}
    
    	return orgService;
    }


    Admin QuikView Solution for CRM 2013

    Thursday, May 29, 2014 6:34 AM