CommunicationException in client-service integration test

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



CommunicationException in client-service integration test



I'm making an integration tests for my WCF service, in which my test client is making requests to self hosted service.



My WCF service setup:


var binding = new BasicHttpBinding Security = Mode = BasicHttpSecurityMode.Transport;
var endpointAddress = new EndpointAddress("https://localhost:44398/MyService.svc");
var host = new ServiceHost(typeof(MyService), endpointAddress.Uri);
host.AddServiceEndpoint(typeof(WcfServices.Contracts.IMyService),
binding, endpointAddress.Uri);
host.Open();



And my client call:


var client = new MyServiceClient(binding, endpointAddress);

// Act

Contract.MyResult result;
try

result = actMethod.Invoke(sut);

finally

client.Close();
if (host.State == CommunicationState.Opened)
host.Close();
else
host.Abort();



Before executing tests, I run this PowerShell script:


$whoami = WHOAMI
netsh http add urlacl url=https://+:44398/MyService.svc/ user=$whoami



Everything works just fine on my local machines, but when it's built with my pipeline in Azure DevOps, and it comes to running this particular test, I get:



System.ServiceModel.CommunicationException : An error occurred while making the HTTP request to https://localhost:44398/MyService.svc. This could be due to the fact that the server certificate is not configured properly with HTTP.SYS in the HTTPS case. This could also be caused by a mismatch of the security binding between the client and the server.



---- 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



Also, I've tried adding this to my test:


if (ServicePointManager.SecurityProtocol == (SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls))
ServicePointManager.SecurityProtocol =
SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;



Without any change.



I get that it may have something to do with the fact I've never used any certificate in pipeline, though I wonder why would it work without one on my local machine then. Also, I don't really know how to properly set up one in pipeline. Could someone give me a hand with solving this issue?









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard