0
votes

I am trying to call WebService Function that exposes an xmlport. I am able to get this to work using C#, but cannot figure it out using PHP.

When I do this in C#, I add a Web Service Reference which exposes my xml port to my project. I basically populate the XML nodes and I can pass it into my Codeunit Web Service. I'm not sure how this could be done in PHP.

I am a Nav Developer that is working on a Web Integration Project with a PHP developer. I don't know much about PHP and he doesn't know much about Navision.

The Top Screenshot is my Codeunit Function that has been exposed as a Web Service. The bottom screenshot is my .Net code. The highlighted area shows that I added a web Service Reference to my project using the URL of the Web Service.

Nav Codeunit :

enter image description here

.Net Code :

enter image description here

2

2 Answers

0
votes

There are a few things you should check. Did you set the authentication method to NTLM? This is done in de CustomSettings.config file of the Dynamics NAV Service and is the only way PHP can authenticate to the NAV webservice.

You should set this value:

 <add key="ServicesUseNTLMAuthentication" value="true" />

There is a working example here: http://blogs.msdn.com/b/freddyk/archive/2010/01/19/connecting-to-nav-web-services-from-php.aspx

0
votes

How to connect with Navision's web services from PHP

Step 1 : Checking your configuration

As gbierkens already pointed out, you need to make sure that NTLM is enabled in the CustomSettings.config file :

<add key="ServicesUseNTLMAuthentication" value="true" />

Step 2 : Sending a HTTP request :

Personally, I don't really like using SoapClient or libraries just to send your HTTP requests and process your responses. If you know how to parse XML in PHP, you could just use cURL and parse the XML responses yourself.

In that case, sending a GET request to your SOAP or Odata service can really be as simple as this :

// Create curl handle
$ch = curl_init(); 

// Set HTTP options
curl_setopt($ch, CURLOPT_URL, $url);  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);   
curl_setopt($ch, CURLOPT_USERPWD, 'username:password'); 

// Get & output response (= XML string)
echo curl_exec($ch);

// Close handle
curl_close($ch);

Step 3 : Parsing your response :

Parsing a SOAP response can be as simple as this :

$xml = simplexml_load_string(str_ireplace(['SOAP-ENV:', 'SOAP:'], '', $response));

Note :

If you don't like reading and writing raw SOAP messages, you could use Navision's Odata services instead.

Not only do I find the Odata protocol a lot more intuitive than the SOAP protocol, it has the additional advantage of supporting Json instead of XML for communicating between server and client, which makes conversion from and to standard PHP arrays or objects easy as pie.