views:

425

answers:

1

I have written a WPF 4.0 windows application that consumes a .net 3.5 WebService. This works fine when the web service in hosted to allow anonymous connections, however the WebService I need to consume when we go live will be held within a website that has Integrated Authentication enabled.

The person running the WPF application will be logged onto a computer within the same domain as the web server and will have permission to see the WebService (without entering any auth info) if browsing to it using a web browser that is NTLM auth enabled.

Is it possible to pass through the details of the already logged in user running the application to the WebService?

Here is the code I'm currently using:

MyWebService.SearchSoapClient client = new SearchSoapClient();
//From the research I've done I think I need to something with these:
//UserName.PreAuthenticate = true;
//System.Net.CredentialCache.DefaultCredentials;
List<Person> result = client.FuzzySearch("This is my search string").ToList();

Any pointers much appreciated.

Here is the error message I get when the call is currently made:

The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Negotiate,NTLM,Digest qop="auth",algorithm=MD5-sess,nonce="+Upgraded+v17{hashremoved}",charset=utf-8,realm="Digest"'.

+3  A: 

So it turns out that the solution to this problem is very simple in my case.

In the binding configuration for WebService in the App.Config file, I changed this:

<security mode="None">
  <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
 <message clientCredentialType="UserName" algorithmSuite="Default" />
</security>

To this:

<security mode="TransportCredentialOnly">
 <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
 <message clientCredentialType="UserName" algorithmSuite="Default" />
</security>

Note I changed the Mode and clientCredentialType attributes.

And in the Code Behind I added this line before calling the method on the WebService:

client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
Tr1stan