3

I'm using Sitecore 9.2 scaled environment on Azure, and am trying to make a console application connects to XConnect, am following this link from Sitecore documentation.

In the part shown in the below code, I added the search indexer server URL in the searchWebAPIClient. However, I'm not sure what should be defined in the other 2 APIs (CollectionWebApiClient and ConfigurationWebApiClient). Also, where to define the reporting, ProcessingEngine, search indexer. server.

Can someone please advise?

var collectionClient = new CollectionWebApiClient(new Uri("https://collect.azurewebsites.net/odata"), clientModifiers, new[] { certificateModifier });
var searchClient = new SearchWebApiClient(new Uri("https://search.azurewebsites/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);
1
  • Please add your code as text not an image. It gives the search engines more to crawl.
    – Richard Seal
    Nov 18, 2019 at 13:45

2 Answers 2

2

You just need to copy below two connection strings from CM app service to your console app to connect to XConnect.

<add name="xconnect.collection"                         connectionString="https://XXXXXXXX-xc-search.azurewebsites.net" />
<add name="xconnect.collection.certificate"             connectionString="blah;blah;" />

and then use xconnect.collection connectionstring in all 3 places as shown below-

var xdbCollectionCert = ConfigurationManager.ConnectionStrings["xconnect.collection.certificate"].ConnectionString;
var xdbClient = ConfigurationManager.ConnectionStrings["xconnect.collection"].ConnectionString;
var odataEndpoint = xdbClient + "/odata";
var collectionEndpoint = xdbClient + "/configuration";

var options = CertificateWebRequestHandlerModifierOptions.Parse(xdbCollectionCert);

var certificateModifier = new CertificateWebRequestHandlerModifier(options);

var clientModifiers = new List<IHttpClientModifier> { new TimeoutHttpClientModifier(new TimeSpan(0, 0, 20)) };

var collectionClient = new CollectionWebApiClient(new Uri(odataEndpoint), clientModifiers, new[] { certificateModifier });
var searchClient = new SearchWebApiClient(new Uri(odataEndpoint), clientModifiers, new[] { certificateModifier });
var configurationClient = new ConfigurationWebApiClient(new Uri(collectionEndpoint), clientModifiers, new[] { certificateModifier });

var cfg = new XConnectClientConfiguration(new XdbRuntimeModel(CollectionModel.Model), collectionClient, searchClient, configurationClient);
4
  • Thank you so much for your answer but I faced another issue when running the project it gives me an error saying (Sitecore.XConnect.XdbCollectionUnavailableException: 'An error occurred while sending the request.' InvalidOperationException: The certificate was not found.) do you know what is wrong Nov 19, 2019 at 10:47
  • @Fatemaelsayed Did you install xConnect's client certificate on your local? To access XConnect from your local, you will require to install client cert or you need to set AllowInvalidCertificate to true which is not recommended. Nov 19, 2019 at 11:59
  • @Surya, do you know if the cert should have the private key? I'm getting the same error and my console app is running on a different VM, so I installed the cert but the private key was not exportable.
    – webber
    Jul 27, 2020 at 19:51
  • @webber private key is not required. It just require the cert to be installed on the system. Jul 29, 2020 at 18:00
0

For all of three API's we need to give XConnect hostname only as I did below.

 var collectionClient = new Sitecore.XConnect.Client.WebApi.CollectionWebApiClient(new Uri("https://XConnect Site hostname/odata"), clientModifiers, new[] { certificateModifier });
 var searchClient = new Sitecore.XConnect.Client.WebApi.SearchWebApiClient(new Uri("https://XConnect Site hostname/odata"), clientModifiers, new[] { certificateModifier });
 var configurationClient = new Sitecore.XConnect.Client.WebApi.ConfigurationWebApiClient(new Uri("https://XConnect Site hostname/configuration"), clientModifiers, new[] { certificateModifier });

Please let me know if getting any issue with it.

1
  • As I mentioned am using a scaled sitecore environment, which means that the XConnect is divided into servers reporting, ProcessingEngine, search indexer... So I dont know which server URL to put in the CollectionWebApiClient, SearchWebApiClient, and ConfigurationWebApiClient Nov 18, 2019 at 12:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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