0

I need to connect Navision to my PHP application. I have tried to use different ways that I have read in forums but none of them works. I don't know if I should use SOAP, cURL or other, could someone please guide me?

Edit:

I have tried the following code and it does not work either.

$opts = array(
'http' => array(
    'user_agent' => 'PHPSoapClient'
)
);
$context = stream_context_create($opts);

$client = new SoapClient('http://URL:7047/DynamicsNAV/WS/COMPANY/Page/mypage?wsdl/', ['trace' => 1, 'cache_wsdl' => WSDL_CACHE_NONE, 'stream_context' => $context ,'user_agent' => 'USERAG', 'soap_version'   => SOAP_1_2]);
$security = array(
    'UserName' => array(
        'UserName'=>'COMPANY\MYUSER',
        'Password'=>'mypass',
    )
);
$client->__getLastResponse();
$header = new SoapHeader('ChannelFactory','Credentials',$security, false);
$client->__setSoapHeaders($header);

$checkVatParameters = array(
    'level' => '01');

$result = $client->checkVat($checkVatParameters);
print_r($result);

try {
    $ret = $client->getAllItm();
    print_r($ret);
}catch(Exception $e){
    echo $e->getMessage();
}

Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from myurl

Fran
  • 1
  • 2
  • What have you tried so far? Please show your code. A quick Google Search brought [this](https://stoneridgesoftware.com/connecting-to-dynamics-nav-web-services-using-php/) as first result. Please read [here](https://meta.stackoverflow.com/q/261592/6273251) for info on how much research effort is expected of you when asking a question here – Andrea Olivato Jul 22 '21 at 12:43
  • Before I asked I did a lot of googling. At the moment I don't have a fixed code as I have tried different ways (including the one you send me). Above all, I need to know what to use, i've tried SOAP, NTMLSoap, cURL... :( – Fran Jul 22 '21 at 13:25
  • At least tell which version of Nav are you using. – Mak Sim Jul 22 '21 at 17:02
  • This one is old but should still work https://stackoverflow.com/a/25357700/1820340 use soapUI to connect to Nav. It will create sample requests for you. And you’ll be able to see what request it is doing, and then recreate them literally with any tool that can do http requests and handle appropriate auth that is set on nav instance. – Mak Sim Jul 22 '21 at 17:07
  • @Mak Sim I have tried and it does not work either. – Fran Jul 23 '21 at 08:56
  • I can’t help you with php. What was the error when you tried soapui? – Mak Sim Jul 23 '21 at 12:20

1 Answers1

0
    $.soap({
        url: "http://url:7047/DynamicsNAV/WS/COMPANY/Page/ws_myws",
        data: {
            user: "user",
            pass: "pass"
        },
        dataType: "jsonp",
    jsonpCallback: "jsonp_callback",
    crossDomain: true,

        HTTPHeaders: {
            'Content-Type': 'application/xml',
            'Server-Protocol':'SOAP'
        },
        success: function (response){
            response = $.format(response.toString(), {method: 'xml' });
            $("#output").text(response);
        }
    })

RESPONSE: http://url/WS/COMPANY/Page/ws_myws net::ERR_CONNECTION_TIMED_OUT

Fran
  • 1
  • 2