I am having trouble consuming a Microsoft Dynamics NAV 2009 SOAP service from PHP.
The PHP is running from a Linux server and I am using SoapClient. Instead of targeting the URL I am using the WSDL .xml that I downloaded from the browser.
I have user credentials to authenticate using BASIC authentication (the same ones I am asked for when accessing the WSDL from the browser). The service administrators tell me that they have disabled NTLM as follows:
<add key="webServicesUseNTLMAuthentication" value="false"></add>
But I keep getting the following response from the server:
HTTP/1.1 401 Unauthorized
Content-Length: 0
Server: Microsoft-HTTPAPI/2.0
WWW-Authenticate: NTLM
Date: Tue, 23 May 2023 10:28:59 GMT
Error: SoapFault exception: [HTTP] Unauthorized in myscript.php:40
Stack trace:
#0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'http://X.X.X...', 'urn:microsoft-d...', 1, 0)
#1 myscript.php(40): SoapClient->__soapCall('myFunction', Array)
This is the simplified code I am using:
<?php
$wsdlPath = 'downloaded.xml';
$context = stream_context_create([
'ssl' => [
// set some SSL/TLS specific options
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
]
]);
$soapOptions = array(
'authentication' => SOAP_AUTHENTICATION_BASIC,
'login' => 'XXXXX',
'password' => 'XXXXX',
'trace' => 1,
"stream_context" => $context,
'soap_version' => SOAP_1_1,
'connection_timeout' => 120,
'cache_wsdl' => WSDL_CACHE_NONE
);
// create a new SoapClient object and set the endpoint URL and options
$soapClient = new SoapClient($wsdlPath, $soapOptions);
// set the SOAP request parameters as an associative array
$requestParams = array(
'generic_param_0' => 'X',
'generic_param_1' => 'Y',
'generic_param_2' => "Z"
);
try {
$response = $soapClient->__soapCall("myFunction", array($requestParams));
echo $response;
} catch (SoapFault $e) {
$response1 = $soapClient->__getLastResponseHeaders();
echo $response1 . "\n";;
echo 'Error: ' . $e;
}
?>
I don't know what is happening. There seems to be one more level of authentication. Has anyone been able to connect to Nav Web from PHP? Thanks in advance.
There is no way to log into Nav 2009 usin basic auth. It is either NTLM or Kerberos, or whatever. If they disabled ntlm it doesnt mean you can use basic auth. You can't. No way. Only windows authentication mechanisms are available for Nav