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/"));
        catch (XdbModelConflictException ex)

        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.

enter image description here

Please see below for stack trace of the error:

at Sitecore.Xdb.Common.Web.Synchronous.SynchronousExtensions.SuspendContextLock[TResult](Func1 taskFactory) at Sitecore.Xdb.Common.Web.Synchronous.SynchronousExtensions.SuspendContextLock(Func1 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()


You need to pass correct certificate on the following line:


Please try this code:

// Valid certificate thumbprints must be passed in
 CertificateWebRequestHandlerModifierOptions options =

 // Optional timeout modifier
 var certificateModifier = new CertificateWebRequestHandlerModifier(options);
 List<IHttpClientModifier> clientModifiers = new List<IHttpClientModifier>();
 var timeoutClientModifier = new TimeoutHttpClientModifier(new TimeSpan(0, 0, 20));


 // This overload takes three client end points - collection, search, and configuration
 var collectionClient = new CollectionWebApiClient(new Uri("https://sc900rev170622_xconnect/odata"), clientModifiers, new[] { certificateModifier });
 var searchClient = new SearchWebApiClient(new Uri("https://sc900rev170622_xconnect/odata"), clientModifiers, new[] { certificateModifier });
 var configurationClient = new ConfigurationWebApiClient(new Uri("https://sc900rev170622_xconnect/configuration"), clientModifiers, new[] { certificateModifier });

 var cfg = new XConnectClientConfiguration(
                new XdbRuntimeModel(CollectionModel.Model), collectionClient, searchClient, configurationClient);
| improve this answer | |
  • Thanks for your response. I have changed the code accordingly. But I'm getting below error now. {"The HTTP response was not successful: Forbidden"} – Sudheer Suggu Dec 5 '17 at 14:25
  • did you modify Thumbprint value? – Vlad Iobagiu Dec 5 '17 at 14:26
  • when you access xconnect from browser what do you see? – Vlad Iobagiu Dec 5 '17 at 14:26
  • I have changed the thumbprint value and I see below while accessing the Xconnect from browser. I can see below response. "0:06:22.5098385" – Sudheer Suggu Dec 5 '17 at 14:31
  • It should work now; did you change on my code urls to your xconnect urls – Vlad Iobagiu Dec 5 '17 at 14:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.