Home > OS >  Generated WCF SOAP client uses current user for windows authentication instead of given credentials
Generated WCF SOAP client uses current user for windows authentication instead of given credentials

Time:08-12

I'm kind of new to the whole WCF and SOAP topic so please be kind.

I'm using a generated SOAP Client with .net6. In another project we successfully worked with the same Web Service using the old .net Framework 2.0 Web References and the same credentials.

Strange enough everything seemed to work fine at first. Until I realized, that it does not use the given credentials to authenticate. Instead it authenticates with my own domain user. I also tried to get it to work with explicitly setting the binding with a BasicHttpBinding but I only could get the same broken logic to work or I got various authentication/protocol/security errors.

So it seems the authentication is basically working. It just doesn't use the provided credentials. So my question is: How can I configure it to work with the provided identity?

I also found out that it might have anything to do with a cached Windows token. But how can I get rid of it. How to prevent caching in the first place?

EDIT: Specified the variable types explicitly.

string url = "http://someServer/AdministrationService.asmx";
AdministrationServiceSoapClient client = new AdministrationServiceSoapClient(
    AdministrationServiceSoapClient.EndpointConfiguration.AdministrationServiceSoap,
    url);

WindowsClientCredential credential = client.ClientCredentials.Windows;

credential.ClientCredential.UserName = "username";
credential.ClientCredential.Password = "password";
credential.ClientCredential.Domain = "DOMAIN";

GetServerInfoRequest getServerInfoRequest = new GetServerInfoRequest
                               {
                                  // some stuff set here
                               };

GetServerInfoRequest getServerInfoReply = await client.GetServerInfoAsync(getServerInfoRequest);

CodePudding user response:

As far as I know, BasicHttpBinding has security disabled by default, but can be added setting the BasicHttpSecurityMode to a value other than None in the constructor. It can be configured according to the instructions in BasicHttpBinding and BasicHttpBinding Constructors.

By default, setting up client credentials involves two steps: determining the type of client credential required by the service and specifying an actual client credential, as described in this document.

CodePudding user response:

After waiting a day it is working. It seems that the cached credentials became invalid somehow.

Strange enough the simple service creation from above is not working anymore. Instead I have to use the following.

var client = new AdministrationServiceSoapClient(
    new BasicHttpBinding()
    {
        Security = new BasicHttpSecurity()
                   {
                       Mode = BasicHttpSecurityMode.TransportCredentialOnly,
                       Message = new BasicHttpMessageSecurity()
                                 {
                                     ClientCredentialType = BasicHttpMessageCredentialType.UserName,
                                 },
                       Transport = new HttpTransportSecurity()
                                   {
                                       ClientCredentialType = HttpClientCredentialType.Windows,
                                       ProxyCredentialType = HttpProxyCredentialType.Windows,
                                   }
                   },
    },
    new EndpointAddress(url));
  • Related