dotnet / dotnet/wcf

HttpClientCredentialType.Ntlm works for net7.0 but not for net472

Open
#4,974 2 comments 0 reactions 1 assignee Claimed by @mconnew View on GitHub
triaged
Dominant language
C#
Stars
1.8k
Forks
576
Avg merge
6d 9h
Merged PRs (30d)
2

Description

I'm trying to call the web service for managing SQL Server Reporting Services (i.e., ReportService2010.asmx). Ultimately, I'm trying to build a WiX custom action for setting up a number of reports during a product install.

In case it matters: I'm using SSRS 2019

I built a proof-of-concept console app that generated the appropriate Connected Services code based on the published WSDL and wired-up all the calls I'd need to make during the installation process to accomplish what I want. It works like a charm.

However, after coding up the custom action, my installer fails with the following error:
```text
Begin DeployReportPolicies.
Machine: localhost
Virtual Path: ReportServer
Url: http://localhost/ReportServer/ReportService2010.asmx
Folder: /THOR
An exception occurred during deployment:The HTTP request is unauthorized with client authentication scheme 'Ntlm'. The authentication header received from the server was 'NTLM'.

Message: The HTTP request is unauthorized with client authentication scheme 'Ntlm'. The authentication header received from the server was 'NTLM'.

Server stack trace:
at System.ServiceModel.Channels.HttpChannelUtilities.ValidateAuthentication(HttpWebRequest request, HttpWebResponse response, WebException responseException, HttpChannelFactory`1 factory)
at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory`1 factory, WebException responseException, ChannelBinding channelBinding)
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object ins, Object outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
```

After some toying around with my proof-of-concept app, I've narrowed down the issue to the fact that it's targeting `net7.0` (so I could take advantage of C#11 and .NET 7 bells and whistles), while the custom action project used for the installer targets `net472`.

I tinkered a little further with my proof-of-concept app, refactoring it to be `net472`-friendly (attached). I can now safely flip the target framework back and forth: `net7.0` succeeds, and `net472` fails with the same exception as above.

The point of failure is `manager.CheckExists` (Program.cs, L25), ultimately failing on the `_client.FindItems` call (ReportServerManager.cs, L60).

Interesting note: when capturing requests, I notice a `net7.0` build will fail two requests with a 401 response but ultimately succeed on a third request, while a `net472` build fails all three with a 401 response. I've also attached Fiddler captures of both.

Oddly, I also notice the two order their HTTP headers differently, though the only _real_ difference is that the `net7.0` run adds a `Cache-Control` header, and the `net472` run adds a `VsDebuggerCausalityData` header.

Obviously, while running the app, you'll need to modify `MachineName`, but `Protocol` and `VirtualPath` are correct for a default SSRS install. Additionally, you'll want/need to modify `ServiceGroupName`, `ReportPath`, and `ImagePath` if you want to run it all the way to the end, but for now I just need to get past the `manager.CheckExists` call. I suspect the remaining requests would succeed if I can get over that hump.

[testssrsmanagementminimal.zip](https://github.com/dotnet/wcf/files/10282397/testssrsmanagementminimal.zip)
[thor_failure_Full.txt](https://github.com/dotnet/wcf/files/10282442/thor_failure_Full.txt)
[thor_Full.txt](https://github.com/dotnet/wcf/files/10282443/thor_Full.txt)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.