How to call a web service using the NTLM authorization scheme?

I call WCF services, so I hope this is a simple question. When calling a web service with the winform.NET 4 client, how do I change the authorization scheme from anonymous to NTLM?

Now I get an exception: An HTTP request is unauthorized using the Anonymous client authentication scheme. The authentication header received from the server was "NTLM".

My goal is to create a small tool that helps me control the data warehouse and TFS 2010 cube. TFS provides the WarehouseControlWebService web service. I can call the service through test mode in the browser when I enter the server. However, I am trying to call the same web service remotely from my desktop. My user account is in the local administrators group on the server.

I created a .NET 4 WinForm with the canonical Button1 and TextArea1. Then I added a service link to the web service and creatively named it ServiceReference1:

Add Service Reference... http://tfssvr:8080/tfs/TeamFoundation/Administration/v3.0/WarehouseControlService.asmx 

And here is my code behind:

 private void button1_Click(object sender, EventArgs e) { // Creating a proxy takes about 3-4 seconds var dwSvc = new ServiceReference1.WarehouseControlWebServiceSoapClient(); // Invoking the method throws an MessageSecurityException var dwStatus = dwSvc.GetProcessingStatus(null, null, null); } 

I get a System.ServiceModel.Security.MessageSecurityException:

The HTTP request is not authorized using the Anonymous client authentication scheme. The authentication header received from the server was "NTLM".

I tried passing my credentials via:

 dwSvc.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential("user", "pass", "domain"); 

and...

 dwSvc.ClientCredentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials; 

I make my way through the WCF documentation, but ... oh boy ... there are many. I hope this is something simple.

Thanks in advance.

+7
source share
2 answers

Set the configuration settings to security mode = "TransportCredentialOnly" and transport clientCredentialType = "Ntlm"

 <system.serviceModel> <bindings> <basicHttpBinding> <binding name="WarehouseControlWebServiceSoap" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"> <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> <security mode="TransportCredentialOnly"> <transport clientCredentialType="Ntlm" proxyCredentialType="None" realm="" /> <message clientCredentialType="UserName" algorithmSuite="Default" /> </security> </binding> </basicHttpBinding> </bindings> <client> <endpoint address="http://tfsServer:8080/tfs/TeamFoundation/Administration/v3.0/WarehouseControlService.asmx" binding="basicHttpBinding" bindingConfiguration="WarehouseControlWebServiceSoap" contract="TfsWarehouse.WarehouseControlWebServiceSoap" name="WarehouseControlWebServiceSoap" /> </client> </system.serviceModel> 
+6
source

You are looking in the right direction. This is a good page with information about some examples of the available authentication methods available: http://man.ddvip.com/web/bsaspnetapp/LiB0087.html . At the very least, this page should give you a few more tips to continue your efforts.

0
source

All Articles