I'm experiencing some odd behaviour (meaning I don't understand what's happening) and I'd like some help fixing it if possible.
We have some Dynamics 365 NAV Business Central web services exposed an secure with an SSL ceritificate, which we're accessing using some standard C# code.
We've added the SOAP proxy to an ASP .NET Webforms application and this is all working as expected.
We then declare an instance of the web service, set the credentials using a new NetworkCredential instance, and set the web service to use PreAuthenticate, then call the method on our service.
public static bool CheckServiceStatus()
{
bool returnValue = false;
try
{
svcWebServiceServer webService = new svcWebServiceServer();
webService.Credentials = new NetworkCredential(Globals.WebServiceUsername, Globals.WebServicePassword, Globals.WebServiceDomain);
webService.PreAuthenticate = true;
webService.FncServiceStatus(ref returnValue);
}
catch (Exception ex)
{
LoggingFunctions.WriteMessageToDisk("CheckServiceStatus error : " + ex.Message);
}
return returnValue;
}
When we look at the logs for this in Fiddler, we se that the service is called twice. The first time the call is made, we get a 401 error which responds telling us we must use NTLM, the second call is then made with a longer NTLM key and the call succeeds and we get our data...
First attempt...
Second attempt...
Can anyone tell me how to make the web service call so it authenticates first time? The 401s are being picked up as a DDOS style attack and then traffic is being blocked.
I have tried changing the way the credentials are passed, but this has made no difference...
public static bool CheckServiceStatus()
{
bool returnValue = false;
try
{
svcWebServiceServer webService = new svcWebServiceServer();
CredentialCache credCache = new CredentialCache();
credCache.Add(new Uri(webService.Url), "NTLM", new NetworkCredential(Globals.WebServiceUsername, Globals.WebServicePassword, Globals.WebServiceDomain));
webService.Credentials = credCache;
webService.PreAuthenticate = true;
webService.FncServiceStatus(ref returnValue);
}
catch (Exception ex)
{
LoggingFunctions.WriteMessageToDisk("CheckServiceStatus error : " + ex.Message);
}
return returnValue;
}