I am trying to create xConnect contact from console application by using xConnect API.I have downloaded the code from url https://github.com/jst-cyr/xConnectTutorial and trying to add the contact to sitecore 9 instance but it is throwing the following error at InitializeAsync method

An error occurred while sending the request. ---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)

The error occurs at following highlighted code enter image description here

  • Can you paste the full code and config? Nov 6, 2018 at 23:45
  • I am just running the code from console application github.com/jst-cyr/xConnectTutorial to my local instance. Nov 7, 2018 at 0:14
  • I dont know if I have enough info to make this an answer. But mt gut says that you have a connection issue to xConnectUrl configured in the App.config. The server running the console application needs to have the same client certificate that xconnect has, and the URL has to be matched to the Subject Name Alternative. Additionally, you have to make sure you dont have any non-self signed certificates in the Trusted Root collection on the xConnect server. I would also look in the xConnect IIS logs and see what the error code is for the request. Should be obvious. Nov 7, 2018 at 0:51
  • I am able to connect with the sitename.xconnect with ssl certificate and my contacts are showing up in the experience analytics.I pass the same thumbprint i use in my actual sitecore instance connection string.config file. Nov 7, 2018 at 0:56

1 Answer 1


Some of the security protocols which are used by .NET console application might have been disabled.Adding the below code which will set the security protocol property to connect with sitecore xConnect will resolve this connection issue.

System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12 | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls | System.Net.SecurityProtocolType.Ssl3;

Add the above code before calling initializeAsync method in your console application.

  • 1
    Thank you very much.you saved my day.Adding this resolved my issue. Nov 7, 2018 at 18:27

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.