0
votes

I just registered for an online 365 trial version.

I copy-pasted the Walkthrough sample code appearing here, and changed the Url, Username and Password values inside the App.config, so that they have the relevant values.

However, I get an exception when calling xrm.SaveChanges():

Content of exception:

An unhandled exception of type 'Microsoft.Xrm.Sdk.SaveChangesException' occurred in Microsoft.Xrm.Sdk.dll

Content of Message:

An unsecured or incorrectly secured fault was received from the other party. See the inner FaultException for the fault code and detail.

Content of Inner Exception:

Code: {System.ServiceModel.FaultCode}, Message: Invalid Request

Stack trace:

at Microsoft.Xrm.Sdk.Client.OrganizationServiceContext.SaveChanges(SaveChangesOptions options)

at Microsoft.Xrm.Sdk.Client.OrganizationServiceContext.SaveChanges()

at CRMSimpleConsole1.Program.Main(String[] args) in C:\Users\home\documents\visual studio 2015\Projects\CRMSimpleConsole1\CRMSimpleConsole1\Program.cs:line 32

at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)

at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)

at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

at System.Threading.ThreadHelper.ThreadStart_Context(Object state)

at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)

at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)

at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

at System.Threading.ThreadHelper.ThreadStart() I also get an exception when calling xrm.Create(): An unhandled exception of type 'System.ServiceModel.Security.MessageSecurityException' occurred in mscorlib.dll

Note that the same happens for any call to the service (e.g., xrm.Create().

I searched for this on the web, and people say it is caused because of wrong time sync. Well, at least in the CRM Settings area, the time zone is correct, so I don't what to do.

2
You registered for a trial of Dynamics 365 and you are checking an example for CRM 2015? Have you checked if the example for Dynamics 365 (CRM 2016) works?Pawel Gradecki
I didnt find one for 2016OfirD
Still it does not justify using example for different version of CRM. In CRM 2016 you should use Xrm.Tooling for connection not Xrm.Client. You should describe what you should try to achieve to get better help, following a tutorial for wrong version of CRM (and making that a problem on StackOverflow) does not make sensePawel Gradecki

2 Answers

2
votes

The Xrm.Client is deprecated and as others have mentioned, the way to connect via a console app is CrmServiceClient, which is in the Microsoft.Xrm.Tooling.Connector library.

Using NuGet you can get the Microsoft.CrmSdk.XrmTooling.CoreAssembly package and you'll be off to the races.

Here are a couple other helpful links:

Build Windows client applications using the XRM tools

Sample: Quick start for XRM Tooling API

And here's a connection string example for Dyn365 online:

<add name="dev26" connectionString="Url=https://dev26.crm.dynamics.com; [email protected]; Password=Pass; AuthType=Office365" />
0
votes

From the connection string given in Microsoft's walkthrough, you must also

  • remove Domain=CONTOSO
  • add AuthType=Office365