Sitecore 9.1 .NetCore 2.1 .Net 4.7.1
Below you will find the hello world console app code to talk to xConnect. You pass it a thumbprint and a url and it will try to initialize a connection. The only issue is that with a normal old school console app I connect fine. But in a Core app I get the dreaded The HTTP response was not successful: Unauthorized
error. Exact same code. Both in the same admin command prompt.
I run the windows as consoleapp.exe
I run the .netcore as dotnet coreconsoleapp.dll
I would not think so, but does core run in an alternate context? If I disable the cert in xConnect, the connect works. So it is definitely that core cannot process the cert properly. I have added code where I reach in the certificate registry and pull the cert, to test permissions and receive no errors on access.
class Program
{
private static void Main(string[] args)
{
MainAsync(args).ConfigureAwait(false).GetAwaiter().GetResult();
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WriteLine("");
Console.WriteLine("END OF PROGRAM.");
Console.ReadKey();
}
private static async Task MainAsync(string[] args)
{
CertificateHttpClientHandlerModifierOptions options =
CertificateHttpClientHandlerModifierOptions.Parse("StoreName=My;StoreLocation=LocalMachine;FindType=FindByThumbprint;FindValue=DC7E10DC79E4BA82B5464BA6D56EED3F11CE7692");
var certificateModifier = new CertificateHttpClientHandlerModifier(options);
List<IHttpClientModifier> clientModifiers = new List<IHttpClientModifier>();
var timeoutClientModifier = new TimeoutHttpClientModifier(new TimeSpan(0, 0, 20));
clientModifiers.Add(timeoutClientModifier);
var collectionClient = new CollectionWebApiClient(new Uri("https://xconnect/odata"), clientModifiers, new[] { certificateModifier });
var searchClient = new SearchWebApiClient(new Uri("https://xconnect/odata"), clientModifiers, new[] { certificateModifier });
var configurationClient = new ConfigurationWebApiClient(new Uri("https://xconnect/configuration"), clientModifiers, new[] { certificateModifier });
var cfg = new XConnectClientConfiguration(
new XdbRuntimeModel(CollectionModel.Model), collectionClient, searchClient, configurationClient);
try
{
await cfg.InitializeAsync();
// Print xConnect if configuration is valid
var arr = new[]
{
@" ______ __ ",
@" / \ | \ ",
@" __ __ | $$$$$$\ ______ _______ _______ ______ _______ _| $$_ ",
@"| \ / \| $$ \$$ / \ | \ | \ / \ / \| $$ \ ",
@"\$$\/ $$| $$ | $$$$$$\| $$$$$$$\| $$$$$$$\| $$$$$$\| $$$$$$$ \$$$$$$ ",
@" >$$ $$ | $$ __ | $$ | $$| $$ | $$| $$ | $$| $$ $$| $$ | $$ __ ",
@" / $$$$\ | $$__/ \| $$__/ $$| $$ | $$| $$ | $$| $$$$$$$$| $$_____ | $$| \",
@"| $$ \$$\ \$$ $$ \$$ $$| $$ | $$| $$ | $$ \$$ \ \$$ \ \$$ $$",
@" \$$ \$$ \$$$$$$ \$$$$$$ \$$ \$$ \$$ \$$ \$$$$$$$ \$$$$$$$ \$$$$ "
};
Console.WindowWidth = 160;
foreach (string line in arr)
Console.WriteLine(line);
}
catch (XdbModelConflictException ce)
{
Console.WriteLine("ERROR:" + ce.Message);
return;
}
// Initialize a client using the validated configuration
using (var client = new XConnectClient(cfg))
{
try
{
}
catch (XdbExecutionException ex)
{
// Deal with exception
}
}
}
}