static public void Main(string[] args) { // The connection to the Organization web service. OrganizationServiceProxy serviceProxy = null; try { // Obtain the target organization's web address and client logon credentials // from the user by using a helper class. ServerConnection serverConnect = new ServerConnection(); ServerConnection.Configuration config = serverConnect.GetServerConfiguration(); // Establish an authenticated connection to the Organization web service. serviceProxy = new OrganizationServiceProxy(config.OrganizationUri, config.HomeRealmUri, config.Credentials, config.DeviceCredentials); CRUDOperations app = new CRUDOperations(); // Create any records that must exist in the database. These record references are // stored in a collection so the records can be deleted later. EntityReferenceCollection records = app.CreateRequiredEntityRecords(serviceProxy); // Perform the primary operation of this sample. app.Run(serviceProxy, records); // Delete all remaining records that were created by this sample. app.DeleteEntityRecords(serviceProxy, records, true); } // Some exceptions to consider catching. //<snippetCRUDOperations3> catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> e) { HandleException(e); } catch (TimeoutException e) { HandleException(e); } catch (SecurityTokenValidationException e) { HandleException(e); } catch (ExpiredSecurityTokenException e) { HandleException(e); } catch (MessageSecurityException e) { HandleException(e); } catch (SecurityNegotiationException e) { HandleException(e); } catch (SecurityAccessDeniedException e) { HandleException(e); } catch (Exception e) { HandleException(e); } //</snippetCRUDOperations3> finally { // Always dispose the service object to close the service connection and free resources. if (serviceProxy != null) { serviceProxy.Dispose(); } Console.WriteLine("Press <Enter> to exit."); Console.ReadLine(); } }
static public void Main(string[] args) { // The connection to the Organization web service. OrganizationServiceProxy serviceProxy = null; try { // Obtain the target organization's web address and client logon credentials // from the user by using a helper class. ServerConnection serverConnect = new ServerConnection(); ServerConnection.Configuration config = serverConnect.GetServerConfiguration(); // Establish an authenticated connection to the Organization web service. serviceProxy = new OrganizationServiceProxy(config.OrganizationUri, config.HomeRealmUri, config.Credentials, config.DeviceCredentials); CRUDOperations app = new CRUDOperations(); // Create any records that must exist in the database. These record references are // stored in a collection so the records can be deleted later. EntityReferenceCollection records = app.CreateRequiredEntityRecords(serviceProxy); // Perform the primary operation of this sample. app.Run(serviceProxy, records); // Delete all remaining records that were created by this sample. app.DeleteEntityRecords(serviceProxy, records, true); } // Some exceptions to consider catching. //<snippetCRUDOperations3> catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault> e) { HandleException(e); } catch (TimeoutException e) { HandleException(e); } catch (SecurityTokenValidationException e) { HandleException(e); } catch (ExpiredSecurityTokenException e) { HandleException(e); } catch (MessageSecurityException e) { HandleException(e); } catch (SecurityNegotiationException e) { HandleException(e); } catch (SecurityAccessDeniedException e) { HandleException(e); } catch (Exception e) { HandleException(e); } //</snippetCRUDOperations3> finally { // Always dispose the service object to close the service connection and free resources. if (serviceProxy != null) serviceProxy.Dispose(); Console.WriteLine("Press <Enter> to exit."); Console.ReadLine(); } }
/// <summary> /// Standard Main() method used by most SDK samples. /// </summary> /// <param name="args"></param> static public void Main(string[] args) { try { // Obtain the target organization's Web address and client logon // credentials from the user. ServerConnection serverConnect = new ServerConnection(); ServerConnection.Configuration config = serverConnect.GetServerConfiguration(); CRUDOperations app = new CRUDOperations(); app.Run( config, true ); } //<snippetCRUDOperations2> catch (FaultException<Microsoft.Xrm.Sdk.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 (System.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 (System.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"); } } } //</snippetCRUDOperations2> // Additional exceptions to catch: SecurityTokenValidationException, ExpiredSecurityTokenException, // SecurityAccessDeniedException, MessageSecurityException, and SecurityNegotiationException. finally { Console.WriteLine("Press <Enter> to exit."); Console.ReadLine(); } }
/// <summary> /// Standard Main() method used by most SDK samples. /// </summary> /// <param name="args"></param> static public void Main(string[] args) { try { // Obtain the target organization's Web address and client logon // credentials from the user. ServerConnection serverConnect = new ServerConnection(); ServerConnection.Configuration config = serverConnect.GetServerConfiguration(); CRUDOperations app = new CRUDOperations(); app.Run(config, true); } //<snippetCRUDOperations2> catch (FaultException <Microsoft.Xrm.Sdk.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 (System.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 (System.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"); } } } //</snippetCRUDOperations2> // Additional exceptions to catch: SecurityTokenValidationException, ExpiredSecurityTokenException, // SecurityAccessDeniedException, MessageSecurityException, and SecurityNegotiationException. finally { Console.WriteLine("Press <Enter> to exit."); Console.ReadLine(); } }