Search code examples
unit-testingvisual-studio-2015http-error

VS 2015 TestMethod The HTTP request was forbidden with client authentication scheme 'Anonymous'


I'm getting the below error when I try to run TestMethod through VS Test explorer (both Pro and Ent editions with Update3) step that calls an external service (attaches certificate). However if I run the same TestMethod using Resharper command (unit test session) it succeeds. It's successful, if I host the application too. The library that calls the external service works fine in another VS 2015 solution.

System.ServiceModel.Security.MessageSecurityException: The HTTP request was forbidden with client authentication scheme 'Anonymous'. ---> System.Net.WebException: The remote server returned an error: (403) Forbidden.

I'm not able to find, what the difference could be between VS 2015 test runner and Resharper's test runner that's resulting in this error. Any pointers/solutions?

Thanks in advance for your time.


Solution

  • The resolution was to add below statement in the method where I make the http call.

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
    

    VSTest runner seems to be using the default Tls12, which was not configured on server and hence the error.