OfirD
OfirD

Reputation: 10460

Calling Dynamics Crm Online XrmServiceContext results in an exception

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.

Upvotes: 0

Views: 1526

Answers (2)

Aron
Aron

Reputation: 3935

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" />

Upvotes: 2

Dave Clark
Dave Clark

Reputation: 2303

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

  • remove Domain=CONTOSO
  • add AuthType=Office365

Upvotes: 0

Related Questions