I have a requirement to create contact and push into XDB using Xconnect.So I'm referring to the blog for my implementation
So when I'm trying to initialize the Xconnect config. It is throwing an exception.
Code Snippet
private static XConnectClient GetClient()
{
var config = new XConnectClientConfiguration(
new XdbRuntimeModel(CollectionModel.Model),
new Uri("https://site.xconnect/"),
new Uri("https://site.xconnect/"));
try
{
config.Initialize();
}
catch (XdbModelConflictException ex)
{
Console.WriteLine(ex.Message);
throw;
}
return new XConnectClient(config);
}
I'm getting following exception while calling the config.Initialize(); as shown below:
The HTTP response was not successful: Unauthorized
I have referred below Post but no luck. My scenario is something different as compared with the question.
Please see below snapshot for the exact error information.
Please see below for stack trace of the error:
at Sitecore.Xdb.Common.Web.Synchronous.SynchronousExtensions.SuspendContextLock[TResult](Func
1 taskFactory) at Sitecore.Xdb.Common.Web.Synchronous.SynchronousExtensions.SuspendContextLock(Func
1 taskFactory) at Sitecore.XConnect.Client.XConnectSynchronousExtensions.SuspendContextLock(Func`1 taskFactory) at Sitecore.XConnect.Client.XConnectSynchronousExtensions.Initialize(XConnectClientConfiguration config) at CreateContact.Program.GetClient() in D:\POC\XconnectPOC\CreateContact\Program.cs:line 65 at CreateContact.Program.AddContact() in D:\POC\XconnectPOC\CreateContact\Program.cs:line 23 at CreateContact.Program.Main(String[] args) in D:\Lexus\POC\XconnectPOC\CreateContact\Program.cs:line 17 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()