Wednesday, August 8, 2018

WCF 'The server has rejected the client credentials'

We are working through a request where our homegrown app is going to be on a different domain than AX.  Up until now, they have been on the same domain.

When testing our WCF connection into our inbound port into AX, we kept getting 'The server has rejected the client credentials'. 

I decided to write a small .NET console app to test and see if I could duplicate this error:

MyServiceReference.MyAXWCFService service = new MyServiceReference.MyAXWCFService();
service.ClientCredentials.UserName.UserName = "myUser@domain.com"
service.ClientCredentials.UserName.Password = "IncorrectPassword"
...
[Call methods from AX]
...

Wierdly, this worked, even though I have an incorrect password. 
After researching I found that it was using the windows credentials of my user that I used to log on to the machine to use VS 2015.

To do this correctly you need do the following:

service.ClientCredentials.Windows.ClientCredential.UserName = "myUser@domain.com"
service.ClientCredentials.Windows.ClientCredential.Password = "IncorrectPassword"

The 'Windows.ClientCredential' is what we need to use to set the Windows Credentials.  When you do this, you will then get the 'The server has rejected the client credentials' error. 

We could then specify the correct credentials in our homegrown app code, on a different domain and it will successfully connect into AX.

Hard coding a username and password like this isnt' the best idea, however, for testing purposes it does show that we can get our WCF across different domains.

No comments:

Post a Comment