0

I'm trying to send a basic HTTP request to an Odata web service in Microsoft Dynamics NAV 2016, using the following PHP code :

$url = 'https://<Server>:<WebServicePort>/<ServerInstance>/OData/Company(\'<CompanyName>\')/customer(\'1\')';
$credentials = 'user:password';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, $credentials);
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Accept: application/json',
    'Content-Type: application/json'
]);
$output = curl_exec($ch);
curl_close($ch);

echo $output;

This code returns the expected result when I execute it on localhost.

However, when I execute this same code on my server, the browser keeps waiting for a response until a timeout.

I also tried using the HTTPful library :

$url = 'https://<Server>:<WebServicePort>/<ServerInstance>/OData/Company(\'<CompanyName>\')/customer(\'1\')';

$response = \Httpful\Request::get($url)
    ->sendsJson()
    ->authenticateWith('user', 'password')
    ->addHeaders([
        'Accept' => 'application/json',
        'Content-Type' => 'application/json'
    ])->send();

echo json_encode($response->body, JSON_PRETTY_PRINT);

Results were the same.

Both localhost and server use PHP5.5 and have cURL enabled, and sending a GET request to eg. http://en.gravatar.com/johnslegers.json works just fine on the server.

Any idea what might cause this and/or how to fix it?

John Slegers
  • 45,213
  • 22
  • 199
  • 169
  • Can your non-localhost server make any outside requests? – Halcyon Mar 03 '16 at 15:15
  • @Halcyon : Sending a GET request to eg. http://en.gravatar.com/johnslegers.json works just fine on the server. – John Slegers Mar 03 '16 at 15:21
  • And other requests to the odata webserivce? – Halcyon Mar 03 '16 at 15:29
  • @Halcyon : I haven't been able to send any requests to this particular Odata service from my server thusfar... and I'm totally clueless if this issue is caused by (1) some obscure setting on my server, (2) some setting in Microsoft Dynamics or... (3) anything else. Any info that could narrow my scope would be helpful. – John Slegers Mar 03 '16 at 15:33
  • Can you contact the people that operate the service? – Halcyon Mar 03 '16 at 15:35
  • @Halcyon : I'm about to send them a mail and plan to contact the hosting company of my web server via chat as soon as I finish that mail. Meanwhile, I've also posted my question at the Microsoft Dynamics NAV Community forum... because I don't have a clue at all which party is responsible for this issue... – John Slegers Mar 03 '16 at 15:42
  • Hi, my recon is that the problem is with the authentication. NAV is using Kerberos by default which is not really supported from PHP. What I always do is to setup a second NAV service tier with basic authentication to the external OData connection. And somebody should check the firewall as well – azatoth Mar 04 '16 at 11:44
  • @azatoth : I believe I have detected the cause of the problem. The Odata web service in Microsoft Dynamics NAV 2016 uses port 1103, whereas port 80, 443, 25 and 110 are the only ports open on the server from which I'm trying to call the service. To help anyone else who might have the same problem, I added this information as an answer. – John Slegers Mar 04 '16 at 17:47

1 Answers1

1

I have detected the cause of the problem :

  • The Odata web service in Microsoft Dynamics NAV 2016 uses port 1103
  • Port 80, 443, 25 and 110 are the only ports open on the server from which I'm trying to call the service

It is not an option for our Microsoft Dynamics provider to change the port they're using, nor an option for our web hosting provider to open this port for us.

After a discussion with my boss, we've agreed to move our web hosting to another provider that gives us more flexibility and does not block port 1103.

John Slegers
  • 45,213
  • 22
  • 199
  • 169