1

I'm currently developing a payment gateway that has to send the order to Navision where it will be managed. In the webservice the NTML authentication is enabled so first it is necessary to extend the native class SoapClient. For it I have found enough documentation in the web https://thomas.rabaix.net/articles/using-soap-php-with-ntlm-authentication that allows to extend this native class.

Now the code exposed in that post does not return me the xslm first.

In this case this would be my code

            define("USERPWD", "user:password");

            require_once("NTLMStream.php");
            require_once("NTLMSoapClient.php");

            
            stream_wrapper_unregister('http');
            
            stream_wrapper_register('http', 'NTLMStream') or die("Failed to register protocol");
            
            // Initialize Soap Client  
            $url = "http://ipaddress:port/DynamicsNAV1_test/WS/enterprise/Codeunit/SalesEnterprise?WSDL";
            $uri = "urn:microsoft-dynamics-schemas/codeunit/SalesEnterprise";

            $params = [
                'stream_context' => stream_context_create([
                       'ssl' => [
                        'verify_peer'=>false, 
                        'verify_peer_name'=>false, 
                        'allow_self_signed'=>true,
                    ]]),
                'cache_wsdl'=> WSDL_CACHE_NONE,
                'trace' => 1,
            ];

            $client = new NTLMSoapClient($url, $params);
            
            stream_wrapper_restore('http');

As you can see I have dispensed with the classes used by this author to define the credentials.

inally the code returns the following error:

SOAP Fault: (faultcode: WSDL, faultstring: SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://ipaddress:port/DynamicsNAV1_test/WS/Enterprise/Codeunit/SalesEnterprise?WSDL' : Document is empty).

I will be happy to provide more information if needed. Many thanks in advance!

naumb
  • 123
  • 9

2 Answers2

0

The first 2 responses you get from an NTLM handshake are 401's with no body, the 3rd response if successfully authenticated will contain the 200 and response.

https://techcommunity.microsoft.com/t5/iis-support-blog/windows-authentication-http-request-flow-in-iis/ba-p/324645


Update 30/1/21

Its been a while since ive used Php, but id start with this post that shows how to manually do the NTLM curl from the shell then how to repeat that same command from php curl - curl with ntlm authentication works in command line but not inside php

Also there are some nuggets in the top few answers of this SO search: https://stackoverflow.com/search?q=NTLM+PHP+curl

MisterSmith
  • 2,884
  • 1
  • 10
  • 13
  • Thanks for the information, but really how should I set up those requests? I do not rule out using curl without this extended SoapClient class, do you have any useful information or practical example about it? – naumb Jan 29 '21 at 13:58
  • @naumb ive extended my answer, sorry i dont have a more concrete solution. Hopefully this is a starting point for you. – MisterSmith Jan 30 '21 at 16:31
  • Thanks you for your help @MisterSmith. I will update the post with a solution very soon, – naumb Feb 09 '21 at 19:20
  • You can take a look at my answer here https://stackoverflow.com/a/68823338/10030693 – Gilbert Aug 17 '21 at 20:00
0

I had this issue with the same SOAP exception, but the code similar to yours was working fine with NAV2013. The company I'm working for upgraded to NAV2020 and then the SOAP Exception appeared. After countless hours of back and forward of refactoring, and researching the web, the solution is on the Microsoft documentation... The issue is that in the original code for NTLMSoapClient class you have to change the following line:

'Content-Type: text/xml; charset=UTF-8'

Which is under the variable $headers in the method processRequest to:

'Content-Type: text/xml; charset=ISO-8859-1'

At some point Dynamics API is no longer accepting credentials with Unicode characters. I hope this works for you as it did for me.

raphie
  • 3,285
  • 2
  • 29
  • 26